Reputation: 3778
I’ve got a simple e-commerce site realized in php without using any e-commerce framework.
I’m trying to track purchases amount and their source (organic, social, paid search) with Google analytics using e-commerce tracking. Purchases are done from paypal. I set the thankyou page correctly and users are redirected to this page after the payment. I use Instant Payment Notification for updating the db with the new purchase and send a confirmation email to the customer.
How could I get the client session data to get correctly these data with:
ga('ecommerce:addTransaction', {
'id': '1234', // Transaction ID. Required.
'affiliation': 'Acme Clothing', // Affiliation or store name.
'revenue': '11.99', // Grand Total.
'shipping': '5', // Shipping.
'tax': '1.29' // Tax.
});
And send them with:
ga('ecommerce:send');
The problem is that if I insert the google analytics tracking code in the thankyou page, the page is not “linked” to the session of the customer because paypal redirect there as a new one, I suppose, and I cannot get the purchase and source data.
I also tried to use measurement protocol in IPN page, and that worked fine, but all the traffic in Google Analytics appear as direct, because these informations are sent from the php page on the server and not from the client browser.
I’m looking for the correct approach to these situation.
Thank you
Upvotes: 2
Views: 369
Reputation: 595
Probably what you are looking for is this.
Google Analytics uses this for its cross-domain tracking, basically it passes the client id from a domain to another through a ?ga=XXXYYYZZZ parameters that links that session to that specific user to bypass the "cross-cookie" situation.
Unfortunately, I do not have experience with IPN but this is probably what you are looking for.
Example:
ga('create', 'UA-XXXXX-Y', 'auto');
ga(function(tracker) {
// Logs the client ID for the current user.
console.log(tracker.get('clientId'));
});
And then you send this clientID in your request and it will be linked by Analytics with the proper information.
Upvotes: 1