Hello!!

The problem is that this part of the Google Analytics code is visible at the bottom of every page in my site:

"pageTracker._trackPageview();"

This is where the Google Analytics code appears on:

</div></div> <!-- /#footer-inner, /#footer -->

   <Google Analytics code>
   
  </div></div> <!-- /#page-inner, /#page -->

</body>
</html>

I also tried moving it before the "body" closing tag just as google suggests, but the code was still viewable.

Anyone know how can I hide this?

Thanks in advance,

Cristian

Comments

davedelong’s picture

Use the Google Analytics module?

fjuqp’s picture

Sorry, I forgot to mention I'm using it.

arh1’s picture

what's the URL?

fjuqp’s picture

This is my site: http://www.thisdir.com/

At the bottom of the page you can see this part of the Google Analytics code:

pageTracker._trackPageview();

I believe it shouldn't be visible, right?

arh1’s picture

the markup is malformed, so the browser is confused and is rendering that code to the screen.

the problem is at line 276: <script type="text/javascript">var pageTracker = _gat._getTracker("UA-4328980-1");pageTracker._initData();<script type="text/javascript">

fix that up and you should be all set. (btw, if you use Firefox, the HTML Validator extension is really handy to catch such errors. otherwise, you can just swing over to the W3C Markup Validation Service any time.)

fjuqp’s picture

I'm not sure about what I should fix. I'm a Javascript newbie.

You tell me the problem is at line 276, the validator says scripts should not be there and Firebug points out the line 279 "unexpected end of XML source". However, Google says the code should be there.

Could you help me with this?

Bye!

arh1’s picture

it's an XHTML problem, not a Javascript problem...

you've got an extra <script type="text/javascript"> in the code i highlighted above. just look closely at the JS snippets you need and be sure all <script> tags have matching </script> tags.

fjuqp’s picture

Hi!

Thank you for your help, arh1.

The Google Analytics module is a little confusing for me. I don't know how to insert my code in there so that it looks exactly like the code Google provided me.

So, I decided to create a block and inserted the Google Analytics code in it. Then I placed it in the closure section. I enabled the block only for anonymous users.

To me, doing it this way provides the same functionality as the module.

Just in case someone finds it useful.

Bye and thanks again for all your help.

arh1’s picture

glad you got it working, cBoy, but i'm curious about your process (should have mentioned this earlier). with the GA module you should not have to add any content to your theme at all, right? you just add your GA user ID at /admin/settings/googleanalytics , and the necessary scripts should be added automatically wherever you print the $closure variable in your theme (should be just above </body>).

the code output on our site (Drupal 5.7; GA 5.x-1.4) is like:

<script type="text/javascript">document.write(unescape("%3Cscript src='http://www.google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));</script>
<script type="text/javascript">var pageTracker = _gat._getTracker("[user ID here]");pageTracker._initData();pageTracker._trackPageview();</script>
<script type="text/javascript" src="/sites/all/modules/google_analytics/downloadtracker.js"></script>
apsivam’s picture

What code?
If you are referring JavaScript code, you cannot and do not want to hide it.
--
Cheers,
Sivanandhan, P. (a.k.a. apsivam)

hass’s picture

***Never*** add GA tracking javascript into the "Custom javascript code" textarea and this would never been happen. Upgrade to 1.6 and you are unable to do such mistakes.