Created
April 14, 2026 16:00
-
-
Save ceaksan/3983c7de397b9d79acd4c30c1b5b27c5 to your computer and use it in GitHub Desktop.
GTM Custom JS Variable: Append ecommerce transaction_id to page_location for order-level debugging in GA4 Explore reports. Platform-agnostic (T-Soft, Shopify, Ticimax, WooCommerce).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * GTM Custom JavaScript Variable — page_location + transaction_id | |
| * File: gtm-page-location-transaction-id.js | |
| * | |
| * What it does: | |
| * Appends the ecommerce transaction ID to the current page URL. | |
| * Used as a page_location override in GA4 purchase tags to enable | |
| * order-level debugging in Explore reports. | |
| * | |
| * Example output: | |
| * https://example.com/order → https://example.com/order/TXN-12345 | |
| * (if no transaction_id) → https://example.com/order | |
| * | |
| * Usage in GTM: | |
| * 1. Create a Custom JavaScript Variable with this code | |
| * 2. In your GA4 purchase tag, set page_location parameter | |
| * to this variable (overrides the default) | |
| * 3. In GA4 Explore, use page_location dimension to filter | |
| * or group by individual orders | |
| * | |
| * Platform support: | |
| * Works on any platform that pushes ecommerce.transaction_id | |
| * to dataLayer: T-Soft (/order), Shopify (/thank_you), | |
| * Ticimax, Ikas, WooCommerce, custom builds. | |
| * | |
| * Note: | |
| * This override is for GA4 reporting only. It does not change | |
| * the actual browser URL or affect other tags. | |
| * | |
| * Requires: | |
| * - {{Page URL}} — built-in GTM variable | |
| * - {{dlv - ecommerce.transaction_id}} — Data Layer Variable | |
| * pointing to ecommerce.transaction_id | |
| */ | |
| function () { | |
| var pageLocation = {{Page URL}}; | |
| var transactionId = {{dlv - ecommerce.transaction_id}}; | |
| var tid = transactionId ? String(transactionId).trim() : ""; | |
| return tid ? pageLocation + "/" + tid : pageLocation; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment