I'm using the theiconic/php-ga-measurement-protocol package and have followed the exact steps as described in the readme, but for reasons I don't quite understand, half of the info does not show up in Google Analytics.
I'm using the following code:
use TheIconic\Tracking\GoogleAnalytics\Analytics;
$trackingID = 'xxxxxxx';
$order = 'obviously an object';
$deal = 'object';
$analytics = new Analytics();
// the Client ID just won't do anything
$analytics->setProtocolVersion('1')
->setClientId($order->gaClientID)
->setTrackingId($trackingID);
// this part works just fine
$analytics->setTransactionId($transactionID)
->setRevenue($order->getTotalPrice(false))
->setTax($order->getTaxCost())
->sendTransaction();
// here it's as if nothing happens
// Yes, it does loop over all the orderRules but it does not show up in Google Analytics
foreach ($order->getOrderRules() as $orderRule) {
$analytics->setTransactionId($transactionID)
->setItemName($deal->name)
->setItemCode($order->dealID)
->setItemCategory($deal->getDealCategoryName())
->setItemPrice($orderRule->getPrice())
->sendItem();
}
And I'm saving the ClientID with this JavaScript into a hidden input:
ga.getAll()[0].get('clientId')
So my issues are basically:
Is there anything I am forgetting? I've had several people looking at it, not being able to find out where it's going wrong.
What I would do:
Enhanced e-commerce : replace your code which is for the old e-commerce with this code which is for enhanced e-commerce. Reason: new (enhanced) is backward compatible with the old and has lots more features, so 0 point of using old e-commerce. Reason 2: the enhanced e-commerce implementation seems "cleaner" in the sense that all the data is sent with 1 single hit at the end ( ->sendEvent();
), whereas the old e-commerce first sends the transaction (->sendTransaction();) then later the products with separate hits ( ->sendItem();
).
Debug : enable debug mode to find out if/why your hits are being rejected by the API.
With enhanced e-commerce it should be something like:
$analytics->setDebug(true)
->setEventCategory('Checkout')
->setEventAction('Purchase')
->sendEvent();
$debugResponse = $response->getDebugResponse();
print_r($debugResponse);
And you should get debug from the API that will look like this:
{
"hitParsingResult": [
{
"valid": false,
"hit": "GET /debug/collect?tid=fake\u0026v=1 HTTP/1.1",
"parserMessage": [
{
"messageType": "ERROR",
"description": "The value provided for parameter 'tid' is invalid. Please see ... for details.",
"parameter": "tid"
},
Filters: if your hits are not rejected by the API (once they are validated you have to remove the debug for them to be actually sent), I would look in GA to check if you don't have filters excluding your hits.
Quotas : although unlikely, I would also check if you haven't reached the API limits hence why your data isn't being collected.
BONUS: User-ID : if people making purchases have created a user account on your website, use your database ID as User ID
: it will be easier to implement (you don't have to reverse engineer the Client ID, use your database ID), and will track the same user regardless of the browser/device used (Client ID is linked to the Cookie, so will be different for each device/browser the user uses, your database ID will always be the same as long as people log in with the same account)
I've tried the enhanced e-commerce again. I've done that before as well, but this time with the debug function on. The client ID gets send properly as seen in hitPersingResult[0]['hit']. But still nothing appears in google Analytics.
Also we're not hitting the limits. I've literally copy pasted the example and this is my response:
Array
(
[hitParsingResult] => Array
(
[0] => Array
(
[valid] => 1
[parserMessage] => Array
(
)
[hit] => /debug/collect?v=1&tid=UA-xxxxxxxx-11&cid=161460xxxx.xxxx180000&uid=161460xxxx.xxxx180000&ti=1802.48511-1518713633&ta=test%20affiliation&tr=206.95&tt=3.4623966942149&ts=0&pa=purchase&ec=Checkout&ea=Purchase&t=event&pr1id=2033&pr1nm=xxxxx&pr1br=brand&pr1ca=xxxxxx&pr1pr=xxx&pr1qt=1
)
)
[parserMessage] => Array
(
[0] => Array
(
[messageType] => INFO
[description] => Found 1 hit in the request.
)
)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.