How to add AdSense Code in Google Tag Manager

How to add Adsense Code in Google Tag Manager

Step by step instructions for implementing Google AdSense Code into a Google Tag Manager (GTM) container and fire it on page view.

How to install Google AdSense [1] using Google Tag Manager (GTM) [2] by creating a variable for the AdSense Client ID and a custom HTML tag for the Adsense code (Google Tag Manager does not support AdSense natively). The final implementation will fire on every page view.

Beware: While it works to ship Google AdSense ads through Google Tag Manager, it is not best practice (not a recommended solution). It is better to implement AdSense directly into your website, as it is more performant and thus user friendly.

Step by step instructions

  1. Within your GTM workspace, select Variables from the menu.
  2. In the User-Defined Variables section, create a new user-defined variable with the name AdSenseClientID.
  3. Set the variable type to Constant. The value to enter is your AdSense Client ID.
  4. Safe the configuration.
  5. Within your GTM workspace, select Tags from the menu.
  6. Create a new Tag called AdSense – Page view – ALL
  7. In the Tag Configuration, set the tag type to Custom HTML. Unfortunately, there is no built-in tag in Google Tag Manager for AdSense.
  8. Copy the AdSense code and paste it in the HTML textbox in Google Tag Manager.
  9. Replace your AdSense client ID with {{AdSenseClientID}}, which will insert the previously defined variable.
  10. In the Triggering section for the tag, select the trigger All Pages with the type Page view.
  11. Safe the configuration.
  12. If applicable, publish your website to a staging or testing environment where you can test the configuration.
  13. Withing your GTM workspace, select Preview to test the changes in preview mode.
  14. Once everything works the way you want it to work, publish to your production environment.

Abbreviations

Abreviations used in this document.

GTM
Google Tag Manager

References

  1. Google AdSense
  2. Google Tag Manager