This is the same problem as http://drupal.org/node/66899 that was closed. All I get in my HTML is:

_uacct = "UA-402254-1";urchinTracker();

My site is http://riscy.biz

Obviously there is something different with my site and other sites but it must be common to this guy http://drupal.org/node/66899

It looks like they got theirs working by manually adding the code into the HTML. The Adsense module works, what could be causing the problem with Analytics?

I'm running 4.7.2, could another module or theme be conflicting?

Comments

Riscy’s picture

I think it could be related to this line:

This exists on my site but not on the example site given in the closed bug.

Riscy’s picture

<script type="text/javascript"><!--
  var BASE_URL = "/";
--></script>

Forgot to use code tags

Riscy’s picture

I fixed it in a dodgy way. For some reason Drupal is ignoring the drupal_set_html_head call so I chucked all the code in the Return:

return '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">_uacct = "'.$id.'";urchinTracker();</script>';

Now Google is happy, but the script reference isn't in the section so probably classed as bad HTML.

TerrenceLP’s picture

Hey it works! Amen, thanks again

nicholasThompson’s picture

Mine was the opposiete way around - The header was working, but not the return. I just put everything in the header (as google suggest you do)

moshe weitzman’s picture

working for me. google suggests putting the js link in the HEAD and the tracking script code at end just before so to my eyes, the module is working as designed.

dsoundmn’s picture

based on the code method that google's system suggests the modification of the function in the following fashion should be a bit more ideal.

function googleanalytics_footer($main = 0) {
  global $user;

  $id = variable_get('googleanalytics_account', '');

  // Check if we should track the currently active user's role
  $track = 0;
  foreach($user->roles as $role) {
    $track += variable_get("googleanalytics_track_{$role}", FALSE);
  }

  // Don't track page views in the admin sections
  if($id && (arg(0) != 'admin') && $track > 0) {

    $prefix = '://www';

    // Are we on a secure page?
    if($_SERVER['HTTPS']) {
      $prefix = 's://ssl';
    }

    $tosend = '<script type="text/javascript" src="http' . $prefix . '.google-analytics.com/urchin.js"></script>';
    $tosend .= '<script type="text/javascript">_uacct = "'.$id.'";urchinTracker();</script>';

    return($tosend);

  }
}
budda’s picture

Assigned: Unassigned » budda
Status: Active » Fixed

You're right, as mentioned on http://www.google.com/support/analytics/bin/answer.py?answer=26908&hl=en

Copy and paste the code segment into the bottom of your content, immediately before the tag of each page you are planning to track.

All the JavaScript code should be in the footer. Funnily the Google Analytics sight itself doesn't follow this rule. Have committed the fix to the 4.7 & CVS branches.

Anonymous’s picture

Status: Fixed » Closed (fixed)