Ever wondered how you can set channels in your Google AdSense ad units based on on-the-spot data like user browser or origin? In this quick tutorial I’ll be showing you how to set AdSense channels in order to track statistics based on user browser types, how they arrived at your site, and pretty much anything else. It all pivots on the google_ad_channel parameter. For those of you who are extra savvy, here’s a summary:
- Build an AdSense ad unit using native code,
- Create AdSense channels for your parameters,
- Use the google_ad_channel parameter to track stats on the right channel.
Build an AdSense Ad Unit With Native Code
Consider the following ad code which would form a regular 300×250.
When you create an ad unit, you’re given a chance to create and assign channels to it. Normally, these channels are going to be set values that are true no matter what. For example, “Medium-Rectangle”, “Above-The-Fold”, and “Articles-Section-Sidebar”. What you can’t seem to set are conditional parameters like “User-Came-From-Google” or “User-On-Firefox”.
Create a Channel for your Parameter
Create a new channel to track what you’re looking to gather stats for. This could be just about anything, but for this example I’m going to create 5 channels
- “Users from Google”,
- “Users from Bing”,
- “Users from Yahoo”,
- “Users from 3rd Party Sites”,
- and “Internal Link – No Referrer”.
When you create these channels, you’ll see that each one has a 10-digit ID number in the “ID” column. Take note of that- we’ll need it later!
Tracking AdSense Metrics by Referrer
In order to attach the appropriate channel ID based on referrer, we need to build code that determines the user’s origin. Consider the following:
Tracking AdSense Metrics by Browser
Use the google_ad_channel Parameter to Track Metrics
At this point, you can just insert your new channel into the ad code using the google_ad_channel parameter. This will append the value to your channels, not overwrite them! So, for example, if you have two channels in your ad unit- “Sports” and “Leaderboard”- you’ll now have 3 channels- “Sports, “Leaderboard”, and “Users from Google”. Note that if you want to use more than one channel, the google_ad_channel parameter is an array of strings, so just stack up your strings as an array and you can get even more powerful reporting!