FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » How To » adding Google analytics
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
adding Google analytics [message #163462] Tue, 02 November 2010 12:05 Go to next message
newbit is currently offline  newbit   China
Messages: 29
Registered: November 2010
Karma: 0
Junior Member
How do I put Google Analytics code into my website? Please let me know which files to edit, as well as exactly where in each file to place the tracking code.

I found something that said to edit /FUDforum/thm/default/tmpl/header.tmpl, but I added the code and it didn't work. Actually, I'd prefer for Google Analytics to be in the footer instead, so as not to slow down page loading times.

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>


Please be clear in your answer, and assume that I know nothing. I've been searching this forum for answers, and it seems like most of you already know the software backwards and forwards, and you frequently abbreviate your answers to others.

[Updated on: Wed, 03 November 2010 01:38]

Report message to a moderator

icon6.gif  Re: adding Google analytics [message #163470 is a reply to message #163462] Wed, 03 November 2010 01:44 Go to previous messageGo to next message
The Witcher is currently offline  The Witcher   United States
Messages: 675
Registered: May 2009
Location: USA
Karma: 3
Senior Member
Unfortunately I cannot answer your question with certainty, however I believe you would need to add your code to the header.tmpl via the Admin Panel > Template Editor > Edit template files >


"I'm a Witcher, I solve human problems; not always using a sword!"
Re: adding Google analytics [message #163471 is a reply to message #163462] Wed, 03 November 2010 01:53 Go to previous messageGo to next message
newbit is currently offline  newbit   China
Messages: 29
Registered: November 2010
Karma: 0
Junior Member
newbit wrote on Tue, 02 November 2010 20:05
I found something that said to edit /FUDforum/thm/default/tmpl/header.tmpl, but I added the code and it didn't work.


Yes, I already tried that. Next trick?
Re: adding Google analytics [message #163472 is a reply to message #163471] Wed, 03 November 2010 01:59 Go to previous messageGo to next message
newbit is currently offline  newbit   China
Messages: 29
Registered: November 2010
Karma: 0
Junior Member
Here's the complete code snippet.


{MAIN_SECTION: header forum page header}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="{DIR}" lang="{LANG}" xml:lang="{LANG}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset={CHARSET}" />
<title>{GVAR: FORUM_TITLE}{VAR: TITLE_EXTRA}</title>
<meta name="description" content="{GVAR: FORUM_DESCR}" />
<base href="{FULL_ROOT}" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="lib.js"></script>
<link rel="stylesheet" href="{THEME_ROOT}/forum.css" type="text/css" media="screen" title="Default FUDforum Theme" />
<link rel="search" type="application/opensearchdescription+xml" title="{GVAR: FORUM_TITLE} Search" href="{FULL_ROOT}open_search.php" />
{VAR: RSS}
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>


This gets:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/atampjq/public_html/fudforum/theme/default/thread.php on line 586


OK, so I search & replace and put \ in front of all the ' in the Google Analytics code, even though the documentation says nothing about doing this. Like so:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push([\'_setAccount\', \'UA-19456515-1\']);
  _gaq.push([\'_trackPageview\']);

  (function() {
    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;
    ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>


This gets:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/atampjq/public_html/fudforum/theme/default/thread.php on line 585

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/atampjq/public_html/fudforum/theme/default/thread.php on line 594

[Updated on: Wed, 03 November 2010 02:15]

Report message to a moderator

Re: adding Google analytics [message #163478 is a reply to message #163472] Wed, 03 November 2010 09:26 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
You are right newbit, its of course supposed to be in footer, not header. The google JS is asyncronous, but still, better to toss in footer - right should be right.

In footer.tmpl, just before </body>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(["_setAccount", "UA-19456515-1"]);
  _gaq.push(["_trackPageview"]);

  (function() {
    var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
    ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
    var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>]


IE - doublequotes instead of singlequotes.


[Updated on: Wed, 03 November 2010 09:27]

Report message to a moderator

Re: adding Google analytics [message #163506 is a reply to message #163462] Thu, 04 November 2010 03:21 Go to previous messageGo to next message
newbit is currently offline  newbit   China
Messages: 29
Registered: November 2010
Karma: 0
Junior Member
Ah, double quotes! I would never, ever, not in a million years, guessed that one. Thanks! I removed the close bracket from the code above and it's working now. Yee-hah!
Re: adding Google analytics [message #186459 is a reply to message #163506] Fri, 08 August 2014 14:38 Go to previous message
whitehatworld is currently offline  whitehatworld
Messages: 1
Registered: August 2014
Location: BD
Karma: 0
Junior Member
Thanks it's working.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Suppress rejection emails ?
Next Topic: uploaded pictures won't show
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Dec 21 17:15:35 GMT 2024

Total time taken to generate the page: 0.03809 seconds