Set AdSense Channels by Browser, Referrer, etc.

Written October 2nd, 2010
Categories: Articles, Scripting / Programming
No Comments »

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:

  1. Build an AdSense ad unit using native code,
  2. Create AdSense channels for your parameters,
  3. Write JavaScript code to detect the value you need to use,
  4. Use the google_ad_channel parameter to track stats on the right channel.

Build an AdSense Ad Unit With Native Code

Creating an AdSense Unit

Creating an AdSense Unit is Easy. Channel setup can be tricky.

Consider the following ad code which would form a regular 300×250.

<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxxxxx1083";
/* Testing 300x250 - Do not target */
google_ad_slot = "1168546099";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

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 an AdSense channel to track 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!

Write JavaScript to Detect Parameter Values

At this point, you’ll need to write JavaScript code to detect the parameter you want to track.  In our case, it’s going to be bucketing where the user is coming from when they load a page.  I’ll also include code for tracking users by browser, but the sky is the limit on this technique!

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:

<script type="text/javascript">
var adsense_referrer = document.referrer;
var adsense_referrer_channel = "0123456789";  // Set a default value, like "Users from 3rd Party Sites" channel.

if (adsense_referrer.search(/google\.*/i) != -1)
    adsense_referrer_channel = "1234567890"; // Set to "Users from Google" channel.

else if (adsense_referrer.search(/bing\.*/i) != -1)
    adsense_referrer_channel = "2345678901"; // Set to "Users from Bing" channel.

else if (adsense_referrer.search(/yahoo\.*/i) != -1)
    adsense_referrer_channel = "3456789012"; // Set to "Users from Yahoo" channel.

else if (adsense_referrer.search(/mrbluesummers\.*/i) != -1 || !adsense_referrer)
    adsense_referrer_channel = "4567890123"; // Set to "Internal Link - No Referrer" channel.
</script>

Tracking AdSense Metrics by Browser

You can follow the above system for assigning a channel value, but the difference here is that you’ll pivot on detecting the name of the user’s browser. There’s an excellent (long) article on how to use JavaScript to detect the user’s browser. It’s a little trickier than working with referrer because there’s so many browsers, so I’ll leave it to you.

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!

<script type="text/javascript"><!--
google_ad_client = "ca-pub-8741444217221083";
/* Testing 300x250 - Do not target */
google_ad_slot = "1168546099";
google_ad_width = 300;
google_ad_height = 250;
google_ad_channel = adsense_referrer_channel;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

W3 Total Cache, YARPP, and mySQL: A deadly combo

Written September 18th, 2010
Categories: Articles, Blog, Scripting / Programming
2 comments

Last night I got an e-mail at 2:00 am from Bluehost stating that my account was being blocked for excessive resource use.  Naturally, I was not happy because it was very late at night, I was a few beers in and couldn’t see straight, and the e-mail was totally out of the blue.  Take a look:

Dear Alejo:

Your web hosting account for **************.com has been deactivated, as of 09/18/2010. (reason: site causing performance problems)

This deactivation was due to a Terms of Service violation associated with your account. At sign-up, all users state that they have read through, understand, and agree to our terms. These terms are legal and binding.

Although your web site has been suspended, your data may still be available for up to 15 days from the date of deactivation; if you do not contact us during that 15 day period, your account and all of its files, databases, and emails may be deleted.

If you feel this deactivation was made in error, or in order to gain access to your account, please call our customer service line as soon as possible at (***) ***-4678.
Please read the following, derived from our Terms of Service agreement, for additional information regarding the matter.

Engaging in any activity that, in BlueHost.Com’s sole and absolute discretion, disrupts, interferes with, or is harmful to (or threatens to disrupt, interfere with, or be harmful to) BlueHost.Com’s services, BlueHost.Com’s business, operations, reputation, goodwill, subscribers and/or subscriber relations, or the ability of BlueHost.Com’s subscribers to effectively use BlueHost.Com’s services is prohibited.

Please review the current copy of our Terms of Service here:
http://www.bluehost.com/cgi/terms

Thank you,
BlueHost.Com Technical Support

I immediately called them up to get more information, and got to talk to a nice gal in tech support right away.  She looked up my account.

Yah, we’re not sure what your site is doing but you’re putting some heavy strain on that mySQL server you’re sharing.

“Absurd! My site only gets a few thousand hits per day.  There’s no way I’m dragging things down.”

Nope, it says right here.  In the last few days you’ve moved 1.9 terabytes in and out of the ****** and ******* tables.

I’ll show these dunderheads.  I logged in to my PHPMyAdmin and quickly found out that she was right.

Well this isn't good.

So a few diagnostics later, we figured out the problem.  My W3 Total Cache (W3TC) plugin was set to automatically pre-cache pages at a rate of 10 pages per minute.  Combined with a relation-intensive plug-in like the Yet Another Related Posts Plugin (YARPP) this meant that the server was hitting the database for the wp_term_relationships table hundreds of times per minute.  This created a stupid amount of database traffic.

I think you may have a point Julie at Bluehost…

The moral of the story here is that you should be really careful with what your plug-ins are doing and how they might interact with each other.  And take frequent backups- you never know when your host will drop a bombshell on you.

MrBluesummers.com Back Online

Written September 12th, 2010
Categories: Blog
11 comments

Thanks for taking the downtime like a trooper.  The website is back online, and better than ever.  I’ve got big plans for this new revision!

For your information, check out the stats below.  Taken before and after the front-end revision.

Performance metrics before and after WordPress theme change

The new site is about 20% as big as the old site, and more flexible, too!

Faster, Faster, Faster

Written June 18th, 2010
Categories: Blog
4 comments

These last few sleepy evenings have been spent making some important but invisible changes to the site. I’ve been tightening up the infrastructure to make things faster and taken almost half of the loading time off the site.

I think later this weekend I’m going to get back to what I do best and maybe write out a tutorial. I can’t say I know what I’m going to do just yet, but I think writing something will get me back into the swing of things. Probably something on mental ray rendering.

Where’d Mr. Bluesummers Go?

Written May 2nd, 2010
Categories: Blog
3 comments

Hey all,

Right now I’m still working on parts of the new 3dCodex.com site. Take a look at the mocks below. Chaos Group got back to me with a demo version of the latest VRay, and I’ll be unboxing that tonight and giving it a thorough investigation. I’ll start writing out a final review and posting it here.

Expect some movement this week!

More Tutorials Pending

Written April 23rd, 2010
Categories: Blog
1 Comment »

Hey all,

Wanted to let you know that I’ll have some more tutorials coming down the pipe soon. I’m also working on the 3d Codex project again so I’ll have updates on that later this weekend.

For now, you can check out my posts on 3dTotal.com and CGSociety.com. I put up the entire Monday Movie lineup and it looks kind of cool to see all of the preview images in one big column.  Feel free to grab your favorites for your blog as I’ll continue to host those images indefinitely.

Quick Update

Written April 15th, 2010
Categories: Uncategorized
No Comments »

Hey guys, still trying to scrape together some time for new tutorials and maybe doing a few more video tutorials outside of the MM series. Noticed that there are tons of missing images for the existing tutorials though- you guys have to let me know about this stuff!

Damage Assessment

Written April 11th, 2010
Categories: Blog
1 Comment »

Alright guys,

The damage is looking pretty bad. I’ve lost all of my original footage to the Monday Movies, the bumper resources (intro, outro), and original scenes. This is in addition to personal stuff like documents, music, videos, etc. I’m in the process of a last ditch effort to un-RAID one of my original drives and try to recover the partition but my magic 8 ball says the outlook isn’t good.

Once I’m done grieving, I’ll try to push out some written tutorials for you while I clear the rubble and rebuild.  Just please, remember, rule #1 of any serious project is to keep offsite backups.  At $50/year/200Gb with Google Docs storage there’s no reason not to.

Better, Faster, Stronger Than It Was

Written November 16th, 2008
Categories: Blog
No Comments »

Hey Everyone!

What do you think of the new look? WordPress is a pretty potent little gig, and it’s free which is outstanding. It’s not as accommodating to advertisements from my end of things, but I think the ability for readers to leave comments and berate me directly is more important. You can now tell me exactly what you think! Nifty, eh?

More to follow!

[EDITORS NOTE] 02-27-2010: Oh irony.  Editing the post that announced the old version of my blog.  :)

WordPress Lesson #1

Written November 10th, 2008
Categories: Blog
No Comments »

I’m writing this blog entry remotely, so I’ll be brief.  Today’s lesson is about the most important piece of WordPress documentation that doesn’t exist anywhere.  I just spent 10 minutes trying to find out how to log in to my blog remotely because I deleted all of the side-bar content while working on the layout yesterday.  By default, the side-bar includes the login link and when it’s gone, it’s gone.

In short, you can get to it by going to http://<Your URL with WordPress>/wp-login.php.  This will take you to the login screen that gets you to the admin panel of your blog.  I realize this might seem kind of obvious on a couple of levels, but I was disturbed how difficult it was to find such a simple yet crucial piece of information once you’ve removed the “Meta” widget from your sidebar.

Cheers.

New site is up

Written September 1st, 2008
Categories: Blog
No Comments »

While not exactly fleshed out, I’ve deployed the new site to get things going. I have a feature list written out on my whiteboard, but I think about 10% of them are actually necessary for this site to function and be useful.

Foremost on my mind is content.

To that end, I would like my first tip to be about a website that I could never do without. If you’ve never been to 3dTotal, I’d suggest opening it in a new tab for future viewing. They have fresh news, free tutorials, and a lot of resources that you can purchase on the cheap. I also volunteer to moderate their forums, where you can get some good feedback on your work. While this community isn’t quite as large as some other sites, you’ll find experienced and understanding people there. I know first-hand that the 3dTotal team really is on your side.

Designed by Alejo "Mr. Bluesummers" Grigera"
©2012 MrBluesummers.com