In order to get better statistics and make use of new "event tracking" of Google Analytics, i have tweaked the ad_image module.
I think that this idea could be developed and improved so any ad can be tracked.
My solution.
change line 19 of ad_image.module to
$ad_image = "<div class=\"image-advertisement\" id=\"ad-$ad->aid\"><a href=\"$ad->redirect/@HOSTID___\" title=\"". check_plain($ad->tooltip) ."\"". ad_link_attributes() ." onClick=\"javascript: pageTracker._trackEvent('Drupal Ads','Click','".$ad->url."');\"><img src=\"$image_path\" width=\"$ad->width\" height=\"$ad->height\" alt=\"". check_plain($ad->tooltip) ."\" /></a></div>"; }
the new code
onClick=\"javascript: pageTracker._trackEvent('Drupal Ads','Click','".$ad->url."');
will track any click on image ads to google analytics. You'll see it in "Content / Event Tracking" as a new event type ("drupal ads"), aside of "outgoing links" and "mail"
any feedback will be aprecciated
Comments
Comment #1
jeremy commentedActive development is only happening in the 6.x-2.x branch. Sounds like an interesting idea, and something that could be added in a more general way to apply to all ad types.
Comment #2
esclapes commentedsusbscribe
Comment #3
Molot commentedMaybe try to create a hook that external module could implement to allow such integration?
Comment #4
imad commentedUpdated hack for 6.x-2.2 version:
Change line 32 of ad_image.module to
Comment #5
shmilov commentedIt is not bad to use trackEvent as you suggested, but I think trackPageview is better, at least for some users needs.
Maybe we should simply add an option to add custom row to an Ad? Or is there another way to do it?
Thanks.
Comment #6
emptyvoid commentedI like where this is going, I could see adding a check if the Google Analytics module is installed you could leverage the global google js on Dom load. That being said, I agree that this functionality should be in a sub-custom module not patched to Ads core.
I could see a set of fields to enable ad-tracking and to enter the code per add. This is useful if you are tracking a specific view or if you have "goals" or "funnels" you can to trigger. Which you may setup on landing pages or at the end of user event (which wouldn't be encapsulated in the Ads module but custom).
On a similar note, I may start researching adding a simple jquery hook to track "click" events on custom HTML ads too. If I figure it out I'll share a patch or post code for it.
Comment #7
Branndon commentedIs there any update to this? I've tried that code at line 32, and it's not tracking events to google analytics Event Tracking.
I've also opened ad.module and changed line 280 to this
[code]$target = array('onclick' => 'window.open(this.href); return false;_gaq.push([\'_trackEvent\', \'Ad Click\', \'Sidebar Ad Click\', \''.$ad->url.' \'])');[/code]
I am novice at JavaScript, and don't know if I did that correctly. I am using the Display Type for the Ads of "Jquery" but I have tried plain Javascript and it didn't work either.
Any advice?
Comment #8
Branndon commentedI've made this code work better for me. I have links open in new windows, and the code above didn't do it, so here is what I did.
Edit ad.module
Change the CASE starting at 279 from this, of course remove the PHP opening and closing tags.
To this:
Comment #9
lrwebks commentedDrupal 6 is EOL and no longer supported. Closing this as outdated for that reason. Thanks for your contribution!