less than a minute read • Updated 2 hours ago
Set up Google Tag Manager for Ecommerce tracking
How to track ecommerce events with Google Tag Manager, including the dataLayer, clean URLs, and cross-domain cookies.
If you prefer Google Tag Manager (GTM), ecommerce events are pushed into the dataLayer for you to use in your GTM tags.
Before you start
Enter your
GTM-XXXXXXtag ID in the Google Tag Manager section at Settings > Integrations. See Set up Google Analytics 4 and Google Ads tracking for the admin steps.When you use a
GTM-tag ID, the GTM initialisation code is included on the cart, checkout, and receipt for you. Do not add the GTM initialisation code to those pages yourself (in the template or the header/footer configuration).
Using the dataLayer
All events (see Google Analytics events and item data reference) are pushed to the dataLayer. In your GTM tag, under More Settings > Ecommerce, enable Send ecommerce data with the data source set to Data Layer. The data is formatted the way Google expects, so it carries over automatically.
Clean URLs
A
virtual_page_locationparameter is passed with every event so you can report clean URLs (for example/cartinstead of/cart?fcsid=abc123). Add it as a User-Defined Variable (Data Layer v2), then pass apage_locationevent parameter using that variable in your Custom Event tags.GTM also receives a
virtual_page_viewevent when the sidecart opens and when the cart, checkout, and receipt load. It includesvirtual_page_locationandvirtual_page_title. Use it if you want clean-URL page views for those steps.
Add custom values to the dataLayer
Use the analytics-gtm-datalayer JS event to add your own values. For example, this adds a parameter foo with the value bar:
javascript
FC.client.on('analytics-gtm-datalayer', function(params) {
params.event_data.foo = "bar";
});Notes
Consent for GTM is configured inside Google Tag Manager, not in the admin. See Set up Google consent mode for customer tracking.
GTM relies on Google's autoLinker to carry the customer session across domains when you use a
*.foxycart.comsubdomain. Custom redirects to the cart or checkout can break that link. The gtag.js integration does not have this limitation, because it maintains the session itself.Set your
*.foxycart.comstore subdomain in your Google Tag domains configuration.If your store subdomain matches your website domain (a custom subdomain), tracking is same-domain and cookies are read normally.