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
Comment #1
hass commentedThis 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.
Comment #2
robbin.zhao commentedyes, 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
Comment #3
robbin.zhao commentedNow 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.
Comment #4
hass commentedSorry , i meent $closure - not footer. See http://drupal.org/node/264927
Comment #5
robbin.zhao commentedThank 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.
Comment #7
akosiana commenteddoes not resolve my issue..
Comment #8
akosiana commentedI 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
Comment #9
hass commentedUse a theme with a $closure variable. Reset the module settings, enter your Google Analytics Web property ID, press Save and you are DONE.