Using Google Tag Manager Macros with Analytics dataLayer and Ecommerce Transaction Variables for Agency Tracking Tags
So you have jumped on board the Google Tag Management Train to help streamline your website’s anlytics needs. You’ve done your research and configured basic analytics and conversion tracking using the dataLayer and your GTM container.
Now you have a 3rd party conversion tracking script/pixel/iFrame from an advertising agency that is NOT on the pre-defined list of Google affiliated or vetted remarketing, display, search, audience or analytics agencies. So now what do you do?
Piggyback Your Existing GTM dataLayer
If you have the following already set up you’ll be able to fairly simply set up custom macros in Google Tag Manager (GTM) to allow for tracking of 3rd party agency conversion tracking tag variables for transaction total and transaction id.
- Universal Analytics set up properly in Google Tag Manager
- Google Universal Analytics Ecommerce Tracking with dataLayer
Macros in Google Tag Manager
Add a Rule in GTM
Create the Rule with a condition to match the conversion page where your Google Analytics Conversion Transaction Tag is firing. Remember that your dataLater must also be present on this page and loading above the Google Tag Manager container script.
Example URL Path using Regular Expressions. Use the URL path on your conversion page and test with RegEx tester like RegExPal to test and confirm your rule is accurate.
And the Tag
Create a ‘Custom HTML Tag‘ in GTM using the firing rule from above. In the HTML input field add your full <script></script>.
And now you’re ready to add the new macro variables where appropriate. I’ve highlighted a few for {{GA – transactionTotal}} below as an example.
Repeat for {{GA – transactionId}} and any other additional macros you create.
Select the document.write option if your script requires this function, as this does and then save, test and publish the GTM container.
Test the Transaction and Confirm Success
Run a transaction and preview with GTM so you can easily see if the values have been added properly.
Select the ‘Pageview’ tab so you can view macros as values instead of it’s name.
As you can see {{GA – transactionId}} was replaced with 326744000006 (the transaction ID) and {{GA – transactionTotal}} was replaced with 25 (the transaction total).
Here is the corresponding Google Analytics Transaction Data.