Install-adsense-with-tag-manager

How To Install Adsense With Google Tag Manager

Running a website can be a rewarding past time, be it professionally or as a hobby. The internet gives anyone with a site and a voice the opportunity to create a business and earn money for their online efforts. One obvious way of monetizing your website is through selling ad placements on your site. Google has made it pretty easy to sell ad space with its Adsense platform but setting it up isn’t always easy.

We’ve heard plenty of moaning on the internet since AdSense Will Discontinued it’s official WordPress Plugin. Publishers were faced with a few options either hard code ad placements into your page template, which you would have to do with other CMS’s, Go all in on Ads with running Double Click placements which can be pretty complex or look for third-party plugins and tools that are able to do the job.

There is, however, another way to install Adsense on your website via Google Tag Manager, if you’re familiar with the tool, it shouldn’t be too hard for you to pull off, it not there is a bit of a learning curve involved.

Disclaimer

Note: Before we begin, I DO NOT recommend this installation method or any method of using Jquery inject ads into a page. The embedding jQuery along with with your ad slows down your website load speed and it also has the potential to cause hard-to-track JavaScript conflicts on your site.

Instead, use native DOM methods to add dynamic ads into your website. So perhaps use it on a test site or just as an experiment before you go all in on ad placements on your site.

How to run Adsense via GTM

In order to run Adsense on your website, you will need to run the universal ad code first and then begin marking out your ad placements on your site. At the moment Tag Manager does not support AdSense natively, but we can add a “Custom HTML Tag”

We use this tag to he adv code with jquery (you don’t need to install jquery in your site since tag manager integrates a limited version of the library).

Adding your auto ad placement code

Auto ads use machine learning to make smart ad placement decisions on your behalf. This lets you add one piece of code just once to your pages. Let Google take care of the rest. If you’re planning on running auto ads on your site via GTM here’s how to do it.

Creating the ad code

  • Head over to your Adsense account
  • Under My Ads Click Content
  • Then Click on Auto Ads
  • Select the type of Ads you want to display
  • Get the universal code

Creating the ad tag

  • Now that you have the code head over to GTM
  • Create a new tag
  • Provide a name
  • Select custom HTML as the tag template
  • Copy and paste the code into the text field
  • Set the trigger to fire on All pages or the pages you want to serve ads on
  • Click Save and Submit to push the code live.

Note: If you’re running an AMP site for mobile you will need to repeat the process under Auto Ads for AMP.  You will not be able to use GTM on AMP templates this will need to be hard-coded into your page templates

Creating the ad code

  • Head over to your Adsense account
  • Under My Ads Click Content
  • Then Click on Ads units
  • Create a new ad unit
  • Give the ad unit a name
  • Then click get the code
  • Copy the specific ad code

Adding your ad placement code

  • Now head over to GTM
  • Click on variables on the left side of the screen within your GTM workspace
  • Create a new user-defined variable and call it asClientID
  • Configure the variable as a Constant. The value to enter is your AdSense Client ID
  • Click on Tags on the left side of the screen within your GTM workspace
  • Create a new Tag – Give it a name IE Adsense
  • Select the Custom HTML tag template and use the code from kbyte.snowpenguin.org/ 
  • Copy and Paste the HTML code shown below into GTM
  • Select the trigger All Pageviews
  • Test your changes in preview mode
  • Once everything is working publish the changes to LIVE.

 

Checking your installation

Once you’re done with your installation I highly recommend installing the Google Publisher Plugin in your chrome browser and link it up to both your Adsense and Analytics accounts. This in-browser tool will help you debug add placements and provide info on your ad performance.

As I’ve said before this isn’t a recommended solution and if it doesn’t work for you please don’t come crying to me mailing me about how it’s not running on your site. Try to be a big boy or girl and hard code install it on your site.

To those site owners using this method successfully, I highly recommend you keep tabs on bounce rate and page load speed before and after installation to make sure you’re not sacrificing traffic for the sake of a shoddy implementation of AdSense.

CONTACT US

If you want to know more about publisher support, site monetization or debugging tools don’t be shy we’re happy to assist. Simply contact us here

About the author

Che Kohler

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.