Using Google Tag Manager Macros with Analytics dataLayer and Ecommerce Transaction Variables for Agency Tracking Tags

vickeryhill3rd Party Integrations, Analytics

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.


Example GTM dataLayer highlighting the existing transactionID and transactionTotal variables and it’s values.

Macros in Google Tag Manager

Add these two custom macros in GTM and note that the ‘Data Layer Variable Name’ matches the variable name in your dataLayer for Google Analytics (GA) Ecommerce Transactions.



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.



Need Help With Your Website or Content Management System?

Contact us for a free 30 minute consultation. Seriously. We love this stuff!