adding Google analytics [message #163462] |
Tue, 02 November 2010 12:05 |
newbit
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
|
|
|
|
|
Re: adding Google analytics [message #163472 is a reply to message #163471] |
Wed, 03 November 2010 01:59 |
newbit
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 |
Ernesto
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.
Ginnunga Gaming
[Updated on: Wed, 03 November 2010 09:27] Report message to a moderator
|
|
|
|
|