I would like to add Google Analytics to my forum....
I have the "agisti" theme and SMF v 1.1.7 installed at http://bigjohnsforum.com
What next?
------
This is the tracking code:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-5393646-3");
pageTracker._trackPageview();
} catch(err) {}</script>
-----
Thanks,
Joe
You need to add in the index.template.php of the theme.
In the template_below area before </body> The code will need to be escaped in order to work in the theme.
Quote from: vbgamer45 on January 06, 2009, 10:11:20 PM
You need to add in the index.template.php of the theme.
In the template_below area before </body> The code will need to be escaped in order to work in the theme.
Thanks for the quick reply. I can not find my template in the themes folder.
I am also clueless as to the syntax to escape the code.
Thanks,
Joe
Located inside your themes/default/index.template.php
If you attach your index.template.php we can do it.
Thanks that is what I call service.
The Google code should be above.
If you need an email
[email protected] should work.
Or attached here.
Thanks,
Joe
Fixed file attached
one question ?? what does Google analytics do ?
Thanks guys it is installed!
It is not showing up yet at GA but as I recall it takes a few hours.
I am perplexed that the file is over 200 characters smaller than the original when
it should be larger.
To answer previous question:
Google Analytics http://www.google.com/analytics/ keeps track of the web traffic to your site.
Joe
Sorry about the confusion but I sent the file from the wrong site!
I found another post that said to paste in the Google code right before the </body> tag and have done
that -- seems to be what you did on the previous file.
Here is the part of the file that I edited:
// The following will be used to let the user know that some AJAX process is running
echo '
<div id="ajax_in_progress" style="display: none;', $context['browser']['is_ie'] && !$context['browser']['is_ie7'] ? 'position: absolute;' : '', '">', $txt['ajax_in_progress'], '</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-5393646-4");
pageTracker._trackPageview();
} catch(err) {}</script>
</body></html>';
}
IT didn't work - I broke the forum and I had to revert back to the original file! So I still need help!
This is the error I get on the forum with the edited file:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in .../Themes/AgistiTheme/index.template.php on line 418
409:
410: echo '
411: </div>';
412:
413: // The following will be used to let the user know that some AJAX process is running
414: echo '
415: <div id="ajax_in_progress" style="display: none;', $context['browser']['is_ie'] && !$context['browser']['is_ie7'] ? 'position: absolute;' : '', '">', $txt['ajax_in_progress'], '</div>
416: <script type="text/javascript">
417: var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
418: document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
419: </script>
420: <script type="text/javascript">
421: try {
422: var pageTracker = _gat._getTracker("UA-5393646-4");
Perhaps it has to do with the " agisti" theme I am using?
Attached is the correct file. ::)
I think that I may have found a better solution that will work with all themes. It is a mod that allows you to paste in text for headers and footers.
http://custom.simplemachines.org/mods/index.php?mod=351
Just past in your Google Analytics code.
Will report back when I see if it works as expected.
Joe
Jan 16. IT IS WORKING and is less trouble than editing each and every them that you have.
Read about the fix, and also read that it didn't work. I'd rather not heavily modify the forum, as it always tends to break mods when you upgrade. How do you "escape" the code? Posting it above </body> didn't quite work for me.
I attached my index.template.php file (CorpAmerica theme), and below is the code.
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-123456-78");
pageTracker._trackPageview();
} catch(err) {}</script>
What's my next step? I changed the tracker code for security reasons.
Quote from: tittiger on January 07, 2009, 05:32:01 PM
Sorry about the confusion but I sent the file from the wrong site!
It took me a while to figure out what had to be escaped, as a test I put in VB's code and it worked, but when I put my own code it it did not. I had a similar problem with phpMyChat recently, and finally figured out that I had to escape the apostrophe's (') with a backslash (\)
Original code from Google
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-228678-4");
pageTracker._trackPageview();
} catch(err) {}
</script>
Escaped from vbgamer45
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-5393646-3");
pageTracker._trackPageview();
} catch(err) {}
</script>
Thank you, jay.clark!
It's really worked for Google Analytics.
It's simply put before any apostrophe's (') the backslash (\)
Example:
Was: '
Become: \'
Worked for me, too. That means it will show up on ALL SMF pages, then?
(thank you!!!)
I can't seem to find the closing </body> tag in the index.template.php. What line is it on? Keep in mind that I have installed the ad management tool.
Thanks.
Well that will depend on which version of smf you are using and which theme.