Google Tag Manager & Analytics
Set up Google Tag Manager (standard or server-side) with Google Analytics 4 for checkout tracking, including server-side purchase events.
Overview
Google Tag Manager (GTM) manages tracking scripts on the checkout. Google Analytics 4 (GA4) credentials are always required alongside GTM because the checkout sends the purchase event server-side via the Measurement Protocol — it cannot be sent from the browser.
Two GTM modes are supported:
- Standard GTM — loads the container from Google's servers (
googletagmanager.com) - Server-side GTM (sGTM) — loads the container from your own sGTM endpoint (e.g. Stape), and routes the server-side purchase event through your sGTM server
Standard GTM Setup
- 1
Log in to Google Tag Manager and create a new container if you don't have one yet.
- 2
Copy the container ID. It is found in the top corner of the GTM workspace and is in the format
GTM-XXXXXXX. - 3
Open Google Analytics and go to Admin → Data Streams. Select your web stream.
- 4
Copy the Measurement ID (format
G-XXXXXXXXXX). - 5
Create an API secret: in the data stream details, scroll down to Measurement Protocol API secrets and create a new secret. Copy its value.
- 6
Make sure your GTM container has a Google Analytics: GA4 Configuration tag that uses the same Measurement ID. This is required for session stitching — linking the server-side purchase event to the customer's browser session.
- 7
Open the checkout's Integration settings in the dashboard, select Standard GTM mode, and enter the container ID, Measurement ID, and API secret.
Server-side GTM (sGTM) Setup
Server-side GTM routes all tracking through your own first-party domain, improving data quality and ad-blocker resilience. You can use a managed provider like Stape or self-host on Google Cloud Run.
- 1
Set up a server-side GTM container with your provider. You will receive a script snippet containing a URL — for example:
https://load.sst.yourdomain.com/abcdef.js?param=value. - 2
Make sure your web container has a Google Tag (GA4 configuration) with your Measurement ID and the
server_container_urlparameter pointing to your sGTM server. This is the standard sGTM setup and is required for both event forwarding and session stitching. - 3
Open Google Analytics and go to Admin → Data Streams. Copy the Measurement ID (format
G-XXXXXXXXXX) and create a Measurement Protocol API secret. - 4
Open the checkout's Integration settings in the dashboard and select Server-side GTM (sGTM) mode.
- 5
Enter your GTM Container ID (format
GTM-XXXXXXX). - 6
Copy the full script
srcURL from the snippet your provider gave you and paste it into the sGTM Script URL field. The sGTM Server URL is auto-derived from the script URL but can be edited if needed. - 7
Enter the GA4 Measurement ID and API secret.
Settings Reference
| Asetus | Kuvaus |
|---|---|
| GTM Mode | Choose Standard GTM, Server-side GTM, or Disabled. |
| GTM Container ID | GTM container identifier in the format GTM-XXXXXXX. |
| sGTM Script URL | sGTM mode only. The full script src URL from your sGTM provider. |
| sGTM Server URL | sGTM mode only. Base URL of your sGTM server. Auto-derived from the script URL. |
| Measurement ID | GA4 property identifier in the format G-XXXXXXXXXX. Must match the Measurement ID in your GTM container's GA4 tag. |
| API Secret | Measurement Protocol API secret. Created in GA4 under Admin → Data Streams → Measurement Protocol API secrets. |
Tracked Events
Client-side (via dataLayer)
The checkout pushes the following events to the GTM dataLayer from the browser. They follow GA4 e-commerce naming conventions.
| Event | When sent | Key fields |
|---|---|---|
| page_view | When a checkout page loads | page_path, page_location, page_title |
| begin_checkout | When the checkout order form opens | currency, value, items[] |
To use these events, your GTM container must have a Google Tag (GA4 configuration) that fires on all pages. The tag picks up the dataLayer events and forwards them to GA4. For sGTM users, this tag should include the server_container_url parameter.
Server-side (via Measurement Protocol)
| Event | When sent | Key fields |
|---|---|---|
| purchase | After a successful payment | transaction_id, currency, value, items[] |
The purchase event is sent directly from our server to GA4 (or through your sGTM server when configured). The items array contains the ordered products with id, name, quantity, and price.
The purchase event is sent server-side automatically — you do not need to create a GTM tag or trigger for it. It is not pushed to the dataLayer, so a GTM purchase trigger will not fire from the browser. GA4 receives the purchase event directly via the Measurement Protocol, linked to the same session as the client-side events.
Session Stitching
The checkout uses the gtag('get') API to capture the GA4 client_id and session_id from the browser. These are sent with the server-side purchase event so that GA4 can link it to the same session as the client-side page_view and begin_checkout events. This ensures accurate funnel and attribution reporting.
Requirement: The Measurement ID entered in the integration settings must match the Measurement ID used in your GTM container's GA4 configuration tag. For sGTM users, this means the GA4 tag in the web container. Without a matching GA4 tag, purchase events are still sent but will appear as separate sessions in GA4 reports.
The customer's personal details (email and name) are sent to GA4 as a SHA-256 hash only if the customer has given analytics consent at checkout. Without consent the event is sent without personal data.
GDPR Consent
GTM and other tracking scripts are only loaded if the customer checks the analytics consent checkbox at checkout. The checkbox appears automatically when GTM or Meta Pixel is configured. Without consent, no tracking data is sent — neither from the browser nor from the server.
Meta Pixel via GTM
You can configure a Meta Pixel tag directly in GTM to use the events sent to the dataLayer. This is an alternative to the direct Meta Pixel integration.
See: Meta Pixel
Overview
Checkout links are the primary way to track sales by channel. The checkout also supports Google Tag Manager (incl. server-side GTM), Google Analytics 4, Meta Pixel, and Meta Conversions API. Tracking integrations are only activated with the customer's GDPR consent.
Meta Pixel
Meta Pixel conversion tracking for Facebook and Instagram advertising.