When using Goolge analytics, there is a bug from analyitcs js code, "Drupal is not defined",
and I found that this bug is from these code,

Drupal.behaviors.gaTrackerAttach = function(context) {
 //.....
}

It was loaded before jQuery and Other Drupal js files.

I used "Optimize JavaScript files" functionality in Drupal, but the googleanalytics.js was not packaged in the same file, so i check the module code, I found there is a problem on adding googleanalytics.js using Drupal_add_js.

line78 googleanalytics.module

drupal_add_js(drupal_get_path('module', 'googleanalytics') .'/googleanalytics.js', 'module', $scope);

So I changed the scope to "header" instead of "footer" in the Google analytics setting page, then everything works well.
I checked the google track code and that js file are still on the footer, so i think there is an improvement which need to be done.

The site i worked is http://www.joke4me.com, now it works well. if need to reduce this problem, i can redo it.
Thanks.

Comments

hass’s picture

Category: bug » support
Status: Needs review » Fixed

This should be a bug in your theme. Make sure $footer comes after $scripts in your page.tpl.php. Additional - if Drupal code is not loaded the GA function will never ever be attached. It will be attached by core drupal.js. Change ga.js back to footer. The header selection is not supported except you can fix it yourself.

robbin.zhao’s picture

yes, thanks.
as your description, I found the problem that it seems GA doesn't work now, on the GA administrator page, i found the traffic went to zero from yesterday.

It is your point? I need to change the ga to footer again and move $footer after the $scripts ?

Thanks

robbin.zhao’s picture

Now I put the $script before the $footer.
There are some problems and could you please give some explanation?

1. If the $script is at the bottom, it will be fast for the page loading, now i put it before the $page, will it effect loading time?
2. what is the $closure? do i need to put before the $footer again? I search some introduction for $closure, but still get the clear answer, thanks again.

hass’s picture

Sorry , i meent $closure - not footer. See http://drupal.org/node/264927

robbin.zhao’s picture

Thank you very much.

with your help and my investigation, I moved the $script before the $closure, prefect!
btw, I understand the $closure and hook_footer and $script.

Thanks.

Status: Fixed » Closed (fixed)

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

akosiana’s picture

does not resolve my issue..

akosiana’s picture

I DID EVERYTHING, SAME PAGE NOT FOUND ERROR, I JUST CREATE A FOOTER BLOCK, PUT THE ANALYTICS CODES AND CHECK ON GOOGLE, SUCCESSFULLY INSTALLED LOL, SOS, I DON'T WANT TO THINK ANYMORE

hass’s picture

Use a theme with a $closure variable. Reset the module settings, enter your Google Analytics Web property ID, press Save and you are DONE.