php-ga-measurement-protocol icon indicating copy to clipboard operation
php-ga-measurement-protocol copied to clipboard

E-commerce data not flowing.

Open Marduuk opened this issue 6 years ago • 16 comments

Hello!

I'm trying to implement php-ga in my web application, I wouldn't normally write here but I'm in really big dead end. In short, my e-commerce data ain't flowing to the analytics site (I get a notification). Of course there can be plenty of reasons why it's that way , but, I made same implementation on testing environment and everything there works fine. There is already javascript implementation of analytics on this app, also I'm using clientID obtained on google developers API console, while I should be using client ID from ga cookie? Could someone give me some tips or possible cause of this problem?

This is what I'm getting from hit validator:

--- DEBUG: '{"hitParsingResult":[{"valid":true,"parserMessage":[],"hit":"\\/debug\\/collect?v=1&tid=UA-4XXXXXXX-1&cid=149XXXXXX-e6aXXXXXXXXXXXXXXXXa.apps.googleusercontent.com&ti=DSHMEGZQ65CR34K&tr=4001.00&cu=PLN&t=transaction"}],"parserMessage":[{"messageType":"INFO","description":"Found 1 hit in the request."}]}

--- DEBUG: '{"hitParsingResult":[{"valid":true,"parserMessage":[],"hit":"\\/debug\\/collect?v=1&tid=UA-4XXXXXXXX-1&cid=149XXXXXXX-e6XXXXXXXXXXXXX.apps.googleusercontent.com&ti=DSHMEGZQ65CR34K&tr=4001.00&cu=PLN&t=item&in=paymentReceived&ic=885&iv=transfer&ip=4001.00&iq=1"}],"parserMessage":[{"messageType":"INFO","description":"Found 1 hit in the request."}]} 


And the implementation itself looks like that:

        $analytics = new Analytics(true);
        $amount = $this->currencyConversionToPLN($eventValue, $currency);
         $analytics
            ->setProtocolVersion('1')
            ->setTrackingId($trackingId)
            ->setClientId($clientId)
            ->setTransactionId($transactionID)
            ->setRevenue($amount)
            ->setAsyncRequest(true)
            ->setCurrencyCode('PLN')
            ->sendTransaction();

        $analytics
            ->setTransactionId($transactionID)
            ->setItemName($eventName)
            ->setItemCode($userSKU)
            ->setItemCategory($eventCategory)
            ->setItemPrice($amount)
            ->setAsyncRequest(true)
            ->setCurrencyCode('PLN')
            ->setItemQuantity(1)
            ->sendItem();

I would really love if someone could give me any tip or clue why it might not be working.

Marduuk avatar Apr 20 '18 10:04 Marduuk

I'm using Enhanced E-commerce, try this (change to your data)

$analytics = new Analytics(true);
$amount = $this->currencyConversionToPLN($eventValue, $currency);
$analytics
       ->setProtocolVersion('1')
       ->setTrackingId($trackingId)
       ->setClientId($clientId)
       ->setTransactionId($transactionID)
       ->setRevenue($amount)
       ->setAsyncRequest(true)
       ->setCurrencyCode('PLN');

$analytics->addProduct([
	'sku' => $product->sku,
	'name' => $product->name,
	'category' => $product->category->name,
	'price' => $product->price * $product->vat,
	'quantity' => $product->amount,
	'position' => 1,
]);

// Don't forget to set the product action, in this case to PURCHASE
$analytics->setProductActionToPurchase();

// Finally, you must send a hit, in this case we send an Event
$analytics->setEventCategory('Checkout')
    ->setEventAction('Purchase')
    ->sendEvent();

JanGalek avatar Apr 20 '18 12:04 JanGalek

Ah thank you will try to do that this way :)

Marduuk avatar Apr 20 '18 15:04 Marduuk

Ayee! It's working thanks! By the way, do you maybe have custom events implementation? :)

Marduuk avatar Apr 23 '18 11:04 Marduuk

np, no i havent custom events, I have this https://github.com/theiconic/php-ga-measurement-protocol/issues/59#issuecomment-383075119 with foreach for addProduct

I like it works ;)

JanGalek avatar Apr 23 '18 14:04 JanGalek

Sweet, thanks again, I've been fighting with that for quite some time :)

Marduuk avatar Apr 23 '18 15:04 Marduuk

np, I gladly helped ;)

JanGalek avatar Apr 23 '18 15:04 JanGalek

Hi, I got some similar problem here.

I trigger my event and see the event into the real-time dashboard but somehow their no any data into Ecommerce Overview.

Here is my code:

	$TrackingId 	= 'SOMETHING';
	$Affiliation 	= 'SOMETHING_TOO';

	$analytics = new \TheIconic\Tracking\GoogleAnalytics\Analytics(true);
	$analytics->setProtocolVersion('1')->setTrackingId($TrackingId)->setUserId('2-00000043')->setTransactionId('123456')
	       	  ->setAffiliation($Affiliation)->setTax(6300*0.05)->setShipping(0)->setRevenue(6300)->setAsyncRequest(true)->setCurrencyCode('TWD');
	$analytics->addProduct(['sku' => '12345','name' => 'testData','category' => 'testData/subTest','price' => 6300,'quantity' => 1,'position' => 1,]);
	
	$analytics->setProductActionToPurchase();
	$analytics->setEventCategory('Purchase')->setEventAction('debug')->sendEvent();
	
	$response = $analytics->setDebug(true)->sendPageview();
	$debugResponse = $response->getDebugResponse();
	print_r($debugResponse);

The result of print_r($debugResponse) is an empty array which is really confusing me. Why will I get an empty array if the event does get in the real-time dashboard?

If anyone can get me a hand that I will be really appreciated.

KOEI5113 avatar Jun 29 '18 04:06 KOEI5113

the solution above is not working only the event gets sent but I get no data in e-commerce overview in the dashboard

mouhsinelonly avatar Oct 05 '18 08:10 mouhsinelonly

I've seen 2 situations where transactions and items did not register:

  • When using a user ID
  • When using an invalid Client ID (must be UUID version 4)

It seems user IDs are no longer allowed for E-commerce transactions and client IDs must adhere to RCF 4122. See William's answer at https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid#2040279 for a small function to generate compliant UUID's.

tnouland avatar Oct 24 '18 11:10 tnouland

Hi all, i have same problems above.. ecommerce data is not tracked on Analitycs

https://pastebin.com/igmP16zb

Just for test, i cloned this script and changed TRACKINGID but is not working https://php-ga-measurement-protocol.readthedocs.io/en/latest/#order-tracking-with-enhanced-e-commerce

Enhanced ecommerce is activated

Debug response seems correct https://pastebin.com/g2hSCpMw

anyone can help me?

augustomurri avatar Oct 31 '18 16:10 augustomurri

Has someone already figured out what could be wrong? Most likely that with the debug mode enabled, no events are sent at all?

initialize and set params code...
$analytics->setDebug(true)->sendEvent();

Although the validation itself sending in this mode says that everything is ok.

Validation

"hitParsingResult": [
    {
        "valid": true,
        "parserMessage": [],
        "hit": "/debug/collect?v=1&tid=myTID&cid=myCID&ti=221243&ta=Online%20payment&tr=779&tt=0&ea=Purchase&pa=purchase&ec=Enhanced%20Ecommerce&ts=0&cu=UAH&t=event&pr1id=tnfT93345-JK3&pr1nm=The%20North%20Face%20Guardian%20Etip%20Glove&pr1ca=perchatki&pr1pr=779.00&pr1br=The%20North%20Face&pr1qt=1"
    }
],
"parserMessage": [
    {
        "messageType": "INFO",
        "description": "Found 1 hit in the request."
    }
]

Send event

"getHttpStatusCode": 200,
"getDebugResponse": {
    "hitParsingResult": [
        {
            "valid": true,
            "parserMessage": [],
            "hit": "/debug/collect?v=1&tid=myTID&cid=myCID&ti=221243&ta=Online%20payment&tr=779&tt=0&ea=Purchase&pa=purchase&ec=Enhanced%20Ecommerce&ts=0&cu=UAH&t=event&pr1id=tnfT93345-JK3&pr1nm=The%20North%20Face%20Guardian%20Etip%20Glove&pr1ca=perchatki&pr1pr=779.00&pr1br=The%20North%20Face&pr1qt=1"
        }
    ],
    "parserMessage": [
        {
            "messageType": "INFO",
            "description": "Found 1 hit in the request."
        }
    ]
}

On debug-page and hit-builder seams ok... ga-validate

ga-hit

ZherebcovSergey avatar Feb 01 '19 09:02 ZherebcovSergey

Any updates here? E-commerce still not working

miksself avatar Jul 02 '19 16:07 miksself

There is a delay of a few hours for analytics to process the information. After more than 5 hours the information appears

clebersantos avatar Sep 24 '20 11:09 clebersantos

I'm using Enhanced E-commerce, try this (change to your data)

$analytics = new Analytics(true);
$amount = $this->currencyConversionToPLN($eventValue, $currency);
$analytics
       ->setProtocolVersion('1')
       ->setTrackingId($trackingId)
       ->setClientId($clientId)
       ->setTransactionId($transactionID)
       ->setRevenue($amount)
       ->setAsyncRequest(true)
       ->setCurrencyCode('PLN');

$analytics->addProduct([
	'sku' => $product->sku,
	'name' => $product->name,
	'category' => $product->category->name,
	'price' => $product->price * $product->vat,
	'quantity' => $product->amount,
	'position' => 1,
]);

// Don't forget to set the product action, in this case to PURCHASE
$analytics->setProductActionToPurchase();

// Finally, you must send a hit, in this case we send an Event
$analytics->setEventCategory('Checkout')
    ->setEventAction('Purchase')
    ->sendEvent();

I have implemented enhanced e-commerce but is not showing on the analytics dashboard. I used the same code but is not working. What must I be doing wrong?

Sadicko avatar Nov 13 '20 16:11 Sadicko

Hello ! I've got the same problem, nothing appears on analytics dashboard. Hit is valid, i tried curl on command line too, everything seems ok.

Did you find a way to sort it out ?

Thanks :) Sebastien

brotherseb avatar Mar 01 '21 11:03 brotherseb

Hey again !

I found what was missing (even if the Hit Builder was considering my hit was OK and the debug url returned that everything was OK too), the client id (cid) is mandatory. The documentation says (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid) "This field is required if User ID (uid) is not specified in the request. ", but even with a uid, it does not work (!).

If it can help somebody...

Sebastien

brotherseb avatar Mar 12 '21 09:03 brotherseb