This patch adds the option to add automatically the code to the head section of the HTML page. If the javascript code isn’t between the head tags the integration between AdSense and Analytics will not work.

More info about the new feature:
http://www.google.com/support/googleanalytics/bin/topic.py?topic=14649

Thanks,
introfini

CommentFileSizeAuthor
googleanalytics.module.patch1.27 KBintrofini
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hass’s picture

Title: AdSense reports in Analytics » AdSense reports integration with Google Analytics
Project: Google Analytics » Google AdSense integration
Status: Needs review » Needs work

Uninstall for googleanalytics_link_adsense is missing. Aside we also need working code for ga.js. Urchin is nearly dead...

Aside - I think this code should better be implemented in the AdSense module! Nobody else need the code in GA... and AdSense module can check if GA is installed and active and show you the form setting in the AdSense config or alter the GA config page + add the required line to HTML HEAD. Therefore moving to AdSense queue. Then you also need to change the variable names.

hass’s picture

Otherwise if the AdSense module don't like to implement this - you could also add window.google_analytics_uacct = "UA-1234-5"; to the GA custom javascript section after GA standard footer code... and we don't need to add anything anywhere... you can find this in GA advanced settings.

introfini’s picture

Hi hass,

A lot of sites have adsense but don't have the adsense module installed (you just need blocks for it, one less module to load).

The code doesn't work if put in the GA custom javascript section because it must be in the the head tag or else it just doesn't work.

I understand your concern about adding one more "thing" to the module, but I think it's really necessary especially for people with a large number of sites. This is a new feature of Google Analytics not of AdSense...

Thanks.

Best regards,
introfini

hass’s picture

I don't think that this needs to be in the head. I'm not sure if it needs to be defined before or after _trackPageview(). As the code simply set a variable and nothing more I'm not sure and it would be good to figure out why it shouldn't work next to _trackPageview().

If you don't use AdSense module how are you adding the AdSense stuff to your site? With a custom block? Maybe I need to understand this logic better... Do you need to define the variable before the AdSense block?

hass’s picture

Ok, must be before GA tracker and before AdSense integration. See http://www.google.com/support/googleanalytics/bin/answer.py?answer=94743...

Variants:
1. You use AdSense module -> AdSense module should add the drupal_set_html_head() stuff if GA is installed.
2. You are hacking your own AdSense blocks. Change the block to PHP mode and add drupal_set_html_head() into this PHP block.

With both variants we don't need to extend GA module. As we are building very modular code the variant 1 is the best I think. If you don't like the module overhead you can go with variant 2, but you are already aware that this lay more maintenance work on your side as in past. Nevertheless I'm open minded to get a better understanding of what you are doing in detail and how you integrate AdSense if you don't use the AdSense module.

jcnventura’s picture

Project: Google AdSense integration » Google Analytics

Hi,

As a co-maintainer of the AdSense module, I have to agree with introfini. Users may be using AdSense ads by copying the HTML directly into their blocks/nodes, without using the adsense module. If you look at http://drupal.org/project/usage/adsense you'll see that only about 3,500 sites use the adsense module (compared with 20,000 for the google_analytics module).

@hass: I see your resistance in adding this to your module, but because of the fact that indeed people are inserting the ads directly, this can't be placed in the adsense module. As to your suggestion to have people insert this directly as PHP, if you take it to the extreme, you could also wipe out your module, as people could always insert the GA code directly using PHP. Be reasonable and make it easy for users, please...

The best we could do in the adsense module is to provide a way in our forms to set the variable defined in this patch (the same setting would then be available under two settings forms).

João

BTW: I marked #276282: Integration with Google Analytics as a duplicate of this feature.

hass’s picture

Version: 5.x-1.x-dev » 7.x-1.x-dev

@jcnventura: the GA module is not that easy as you are writing. It does *much* more in the background than adding a simple link to the footer + GA number + tracker! 3500 AdSense module users sounds a resonable number - nevertheless I haven't expected so much people cluttering their site with this ugly ads. It cannot be the very few cents they may receive per month from google. But never mind...

I will think about this again and kicking the issue to D7 as it would need to be backported from there.

hass’s picture

@introfini: I have a few question and suggestions about your patch:

1. Is there any reason why are you not using drupal_add_js() with inline?
2. Should users be able to configure a different UA-ID then the current sites one? Not sure if this is important, but I expect some others may ask for this. But we can wait for this day...
3. Rename googleanalytics_link_adsense to googleanalytics_trackadsense for been consistent.
4. Uninstall need to be added.
5. Move the checkbox up - directly below Site search checkbox.
6. If checked, it will link this account to AdSense. should be more explanatory. Something like If checked, your AdSense ads will be tracked in your Google Analytics account.
7. Link to AdSense should be named Track AdSense ads
8. Code style must be like Drupal core.

Please provide patches for all versions.

Pushkar Gaikwad’s picture

Is the code working ? can I use it on live drupal 5.7 sites ?

hass’s picture

It needs work. See #8

hass’s picture

@introfini: Are you able to provide some feedback to #1 and #2 in comment #8, please?

introfini’s picture

Hello hass,

I'm sorry for my absence; I'm with a big project in hands. I'll try to complete this patch during the next couple of weeks.

Thanks,
introfini

hass’s picture

I can do this for you, but I need your feedback regarding the above points.

introfini’s picture

#1: no, none. it's important that $scope = 'header' or else it won't work.
#2: no I don't see any reason to do so besides trying to inflate the earnings of a particular site.

Thanks for taking care of this issue and my apologies once more for leaving this issue unanswered.

introfini

hass’s picture

Status: Needs work » Fixed

Fixed in CVS for all versions. Please test and report back if it works.

introfini’s picture

I can confirm that it works.

Thanks!

introfini

hass’s picture

Great, thx

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.