News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

I would like to add Google Analytics to my forum

Started by tittiger, January 06, 2009, 09:57:57 PM

Previous topic - Next topic

tittiger

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

vbgamer45

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.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

tittiger

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

vbgamer45

Located inside your themes/default/index.template.php
If you attach your index.template.php we can do it.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

tittiger

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

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

sAce

one question ?? what does Google analytics do ?

tittiger

#7
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

tittiger

#8
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.   ::)

tittiger

#9
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.

skyline5k

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.

jay.clark

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>
SMF 1.11- SMF 2.0 RC2/RC3 - - RSS Feed Poster 2.2,RSS Feeder 1.1.4, Downloads System Pro 1.0.17.1, SMF Classifieds 1.3.5, SMF Gallery Pro 3.0.2, SimpleDesk - Integrated Helpdesk for Simple Machines Forum 1.0 Felidae, Aeva Media 1.1b, Ultimate Profile     0.9, Google Analytics Code 1.1, Twitter and Facebook Publisher mod 2.4, Stop Spammer 2.3.7, SMF Links 2.2, Site map 2.1.2, AjaxChat Integration 3.2.1, Ad Management 2.3.6

SMF (Donated) SMF Links (donated) - Ad Manager (donated) - phpMyChat (donated)

flash_os

Thank you, jay.clark!
It's really worked for Google Analytics.
It's simply put before any apostrophe's (') the backslash (\)


Example:

Was: '
Become: \'


STS

Worked for me, too. That means it will show up on ALL SMF pages, then?

(thank you!!!)

llckll

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.

Tyrsson

Well that will depend on which version of smf you are using and which theme.
PM at your own risk, some I answer, if they are interesting, some I ignore.

Advertisement: