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

Home » FUDforum » How To » adding Google analytics
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
adding Google analytics [message #163462] Tue, 02 November 2010 08:05 Go to next message
newbit is currently offline  newbit   China
Messages: 29
Registered: November 2010
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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: Tue, 02 November 2010 21:38]

Report message to a moderator

icon6.gif  Re: adding Google analytics [message #163470 is a reply to message #163462] Tue, 02 November 2010 21:44 Go to previous messageGo to next message
The Witcher is currently offline  The Witcher   United States
Messages: 662
Registered: May 2009
Location: USA
Karma: 2
Senior Member
add to buddy list
ignore all messages by this user
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] Tue, 02 November 2010 21:53 Go to previous messageGo to next message
newbit is currently offline  newbit   China
Messages: 29
Registered: November 2010
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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] Tue, 02 November 2010 21:59 Go to previous messageGo to next message
newbit is currently offline  newbit   China
Messages: 29
Registered: November 2010
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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: Tue, 02 November 2010 22:15]

Report message to a moderator

Re: adding Google analytics [message #163478 is a reply to message #163472] Wed, 03 November 2010 05:26 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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 05:27]

Report message to a moderator

Re: adding Google analytics [message #163506 is a reply to message #163462] Wed, 03 November 2010 23:21 Go to previous messageGo to next message
newbit is currently offline  newbit   China
Messages: 29
Registered: November 2010
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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 10:38 Go to previous message
whitehatworld is currently offline  whitehatworld
Messages: 1
Registered: August 2014
Location: BD
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Thanks it's working.
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Suppress rejection emails ?
Next Topic: uploaded pictures won't show
Goto Forum:
  

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

Current Time: Fri Oct 20 23:21:18 EDT 2017

Total time taken to generate the page: 0.00658 seconds