Last updated on
17 May 2021
To add the Google remarketing tag in DTM, the recommended approach is with a page load rule in DTM. Below is an example of the Google remarketing Tag. For more information on Google remarketing check out Google's documentation here.
<script type="text/javascript"> /* <![CDATA[ */ var google_conversion_id = XXXXXXXXX; var google_custom_params = window.google_tag_params; var google_remarketing_only = true; /* ]]> */ </script> <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"> </script> <noscript> <div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXX/?value=0&guid=ON&script=0"/> </div> </noscript>
To add the remarketing tag in DTM, complete the following:
- Add a page load rule in DTM by going to Rules > Page Load Rules > Create New Rule
- Expand the JavaScript / Third-Party Tags section and add the following code in the Non-Sequential JS tab
- Save, Test, and Publish the Rule
Note:
If you are deploying the remarketing tag async instead of using conversion.js, call conversion_async.js, then add additional coding to ensure the file loads before you reference it. More information on this approach in the Google documentation here
var dcJS = document.createElement('SCRIPT'); var done = false; dcJS.setAttribute('src', '//www.googleadservices.com/pagead/conversion_async.js'); dcJS.setAttribute('type','text/javascript'); document.body.appendChild(dcJS); dcJS.onload = dcJS.onreadystatechange = function () { if(!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) { done = true; callback(); // Handle memory leak in IE dcJS.onload = dcJS.onreadystatechange = null; document.body.removeChild(dcJS); } }; function callback(){ if(done){ /* <![CDATA[ */ window.google_trackConversion({ google_conversion_id : XXXXXXX, google_custom_params : window.google_tag_params, google_remarketing_only : true }); //]]> } }