Skip to content

Commit 9cc8abe

Browse files
committed
Merge branch 'master' of github.com:theiconic/php-ga-measurement-protocol
2 parents 2e9a0fb + bccb631 commit 9cc8abe

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,42 @@ $analytics
108108
->sendPageview();
109109
```
110110
This means that we are sending the request and not waiting for a response. The AnalyticsResponse object that you will get back has NULL for HTTP status code.
111+
### Order Tracking with simple E-commerce
112+
```php
113+
use TheIconic\Tracking\GoogleAnalytics\Analytics;
114+
115+
$analytics = new Analytics();
116+
117+
// Build the order data programmatically, including each order product in the payload
118+
// Take notice, if you want GA reports to tie this event with previous user actions
119+
// you must get and set the same ClientId from the GA Cookie
120+
// First, general and required hit data
121+
$analytics->setProtocolVersion('1')
122+
->setTrackingId('UA-26293624-12')
123+
->setClientId('2133506694.1448249699');
124+
125+
// To report an order we need to make single hit of type 'transaction' and a hit of
126+
// type 'item' for every item purchased. Just like analytics.js would do when
127+
// tracking e-commerce from JavaScript
128+
$analytics->setTransactionId(1667) // transaction id. required
129+
->setRevenue(65.00)
130+
->setShipping(5.00)
131+
->setTax(10.83)
132+
// make the 'transaction' hit
133+
->sendTransaction();
134+
135+
foreach ($cartProducts as $cartProduct) {
136+
$response = $analytics->setTransactionId(1667) // transaction id. required, same value as above
137+
->setItemName($cartProduct->name) // required
138+
->setItemCode($cartProduct->code) // SKU or id
139+
->setItemCategory($cartProduct->category) // item variation: category, size, color etc.
140+
->setItemPrice($pos->price)
141+
->setItemQuantity($pos->qty)
142+
// make the 'item' hit
143+
->sendItem();
144+
}
145+
146+
```
111147
### Order Tracking with Enhanced E-commerce
112148

113149
```php

0 commit comments

Comments
 (0)