PHP code example of setono / google-analytics-events
1. Go to this page and download the library: Download setono/google-analytics-events library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
setono / google-analytics-events example snippets
use Setono\GoogleAnalyticsEvents\Event\PurchaseEvent;
use Setono\GoogleAnalyticsEvents\Writer\GtagWriter;
$event = PurchaseEvent::create('TRANS_1234')
->setCurrency('USD')
->setValue(123.45)
->setTax(10.45)
->setShipping(3.32)
->addItem(Item::create()->setId('SKU1234')->setName('Blue t-shirt'))
;
$writer = new GtagWriter();
echo $writer->write($event); // output: gtag("event", "purchase", {"currency":"USD","transaction_id":"TRANS_1234","value":123.45,"shipping":3.32,"tax":10.45,"items":[{"item_id":"SKU1234","item_name":"Blue t-shirt","quantity":1}]});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.