I'm developing a Prestashop e-commerce and I want integrate it with Google Analytics.
I've created a OrderConfirmationController.php override that provides the order data I want to send to Google Analytics.
Then, in order-confirmation.tpl I'm sending the Analytics event with the Tag Manager code.
It's working almost fine, because most of the users keep tracked. But I see there are orders that aren't being tracked. Maybe when a users pays with PayPal they can exit the browser and Prestashop doesn't render order-confirmation.tpl (so the event is not sent).
Where is the correct place to send the event?
Thank you, greetings.
You need to use hook actionObjectOrderAddAfter which is called after an order creation and has all necessary information about the order.
public function hookActionObjectOrderAddAfter($order)
{
// $order is an object
your code here
}
I cannot check exactly your PayPal module but I think it should work
Related
I have installed the google analytics in our e-commerce site using google tag manager. From the product detail page you can click on the colors to see the same product in the different colors. I implemented this using ajax so the page load is not required. I was curious if the google analytics will count as multiple reviews a user clicks on the different colors or do I need to explicitly call something in order for the GA to count as multiple reviews.
First of all, that depends how and what kind of GA you've implemented.
To implement analytics, you have to specify a trigger for the analytics tag. That trigger normally determines if a tag is fired or not.
If you used a page load trigger, then the tag will only be triggered on the real page load. And it won't be triggered on your ajax manipulations.
With only one exception: if you used the GA4 config tag, you had this checkbox there:
The checkbox doesn't only send the pageview on config load, it keeps sending pageviews on every history change. Therefore, if your ajax causes history change and you use the GA4 config tag, then you're getting pageviews.
But this is theory. You can just go and check. Open your network tab, filter the request by collect and see what's sent when. Or alternatively, install the adswerve datalayer debugger and it will log whatever is sent whenever it's sent into the console in a very neat, clean way. This is how it works on this page:
I have settled my google tag manager as from the guide.
I have got in place a page that redirect just after the tag gtm-load is collected into the dataLayer. It's actually a "transition" page that should redirect instantaneously.
In this way I make sure google-analytics.com/r/collect is called, as I can see from the network ta of my browser, seems the only way to do so for an "instant redirect page".
However I need to test it from the back-end side.
Is there any way to have a feedback from Google Analytics about the data is actually sent? For example something like google-analytics.com/get/data/lastEntry, so that I can use a restAPI to check it out?
As far as I know, google analytics provide only metrics through a web page, and no actual data sent to.
Moreover there are some Rest API here but they are only for configuration purpose.
you might pass a JavaScript function as a hitCallback parameter of analytics send command and it will be called right after hit data were sent:
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#hitCallback
Here's an example of how to use it with GTM alongside another useful feature of eventcallback
https://www.simoahava.com/gtm-tips/hitcallback-eventcallback/
Hope this helps.
There is a realtime API in Google Analytics, so what I have done for testing is to call my test URL with utm campaign parameters attached. Then I made a call to the realtime API and filtered by my custom campaign.
The realtime API is fairly limited (no session based values, obviously, you cannot test custom dimensions etc), but at least this tells you if your hit has registered in GA.
We provide an iframe-based embeddable widget to our clients and want to be able to send their Google Analytics account events based on what is happening inside our iframe. We used to be able to do this using the old ga.js with the following code:
_gaq.push(['NAMESPACE._setAccount', CUSTOMER_GA_ACCOUNT_ID]);
_gaq.push(['NAMESPACE._setDomainName', CUSTOMER_DOMAIN]);
_gaq.push(['NAMESPACE._trackEvent',"category", "event", "label"]);
This code would be fired inside our iframe, but would result in an event being pushed to the customer's google analytics account, letting them have some insight into customer behavior inside our embeddable widget. The NAMESPACE in front of the actions would keep these events separate from our GA stuff, and would prevent our GA stuff from going to their GA account. They would provide us with their Google Analytics account ID when they wanted to enable this feature.
Is there a way to do something similar with the new Universal Analytics API?
I don't seem to see a similar way to namespace actions and the cross-domain tracking documentation doesn't indicate how to send events/pageviews to two domains/GA accounts (ie we want to track pageviews on our GA account, and send the events to our customer's GA account).
I suggest going the roundabout way - set a pixel in your widget and make the actual endpoint for that pixel a script on your server that sends the data via the measurement protocol to your clients analytics account.
Basically, we use affiliate products. When we get a return call from their servers saying we have a sale, we want to send that information back into GA. Right now we can do that just by loading the page with ecommerce tracking and tacking on UTM parameters in the link based on the user who purchased...
One big thing we want to do though is actually send back the device information the user purchased with back to analytics. we capture it in our custom CRM, I'm just not sure how we can pass it back to analytics. using valuetrack parameters in the URL doesn't work, and i'm not sure how to modify the ecommerce code to figure this out.
Any help is appreciated!!!
I've set up GA ecommerce tracking by putting the required JavaScript code on my order receipt page. However, if the user reloads the page (or arrives to it without actually completing a purchase), won't the order be counted again?
How can I make sure each order is counted once and only once?
First off, your application should probably be designed in a manor that would not allow users to access an "Order Placed" type page directly, they should only be able to get there as a result of shopping cart checkout process. Depending on your server technology, you can usually limit this by only accepting specific HTTP Verbs (methods) such as only allowing POST operations.
Secondly, check out the addTrans()documentation. So if your application allows users to refresh a page that is tracking transactions, then logging the exact same ecommerce data for the same orderId will just overwrite the old data with the new data - which may be the same depending on how your app is structured.
Either way, I strongly recommend not allowing your users to refresh this page if you that is where you are tracking Google Analytics. When an order is placed on our website, we clear out the shopping cart and return the user to an order receipt page with the GA ecommerce tracking. Then, if anybody tried accessing that page again and their cart is empty, the get redirected to the "Orders" page where they can review recently placed orders (no GA ecommerce).
Hope this helps!