Skip to main content

How to add Adsense in Google Tag Manager

Summary

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

While you can ship Google AdSense ads through Google Tag Manager, it is not a recommended solution. It is better to implement AdSense directly into your website, as it is more performant and thus user friendly.

That is why Google Tag Manager does not support AdSense natively.

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.

Background #

Google AdSense is a program that allows website owners to display relevant advertisements on their websites and earn revenue from clicks on those ads. Advertisers use the Google AdWords program to create and display ads, and website owners can sign up for AdSense to display those ads on their sites. AdSense uses an algorithm to determine which ads to display based on the content of the website and the interests of the website’s visitors. This allows website owners to earn money without having to actively sell advertising space.

Google Tag Manager (GTM) is a tool that allows users to add and manage marketing and analytics tags on their website without having to edit the website’s code. GTM allows users to create and manage tags for various purposes, such as tracking website visitors, measuring website performance, and displaying targeted advertising. GTM also allows users to preview and test tags before publishing them to the website. This can streamline the process of adding and managing tags and make it easier for users to make changes to their website’s tracking and advertising setup.

Both AdSense and GTM are products offered by Google, and they can be used together to create a more effective online advertising strategy. Website owners can use AdSense to display relevant ads on their site and use GTM to track the performance of those ads and make adjustments as needed. This can help website owners optimize their advertising revenue and provide a better experience for their visitors.


Further readings #

Sources and recommended, further resources on the topic:

Author

Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See: https://www.j15k.com/

License

License: How to add Adsense in Google Tag Manager by Jonas Jared Jacek is licensed under CC BY-SA 4.0.

This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:

<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/instructions/how-to-add-google-adsense-code-in-google-tag-manager">How to add Adsense in Google Tag Manager</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>

For more information see the DITig legal page.


“Form ever follows function.”

Louis Henry Sullivan, American architectThe Tall Office Building Artistically Considered, - IT quotes