Advertisement:

Author Topic: I would like to add Google Analytics to my forum  (Read 10671 times)

Offline tittiger

  • Semi-Newbie
  • *
  • Posts: 53
I would like to add Google Analytics to my forum
« on: January 06, 2009, 09:57:57 PM »
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

Online vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 20,211
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: I would like to add Google Analytics to my forum
« Reply #1 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.
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

Offline tittiger

  • Semi-Newbie
  • *
  • Posts: 53
Re: I would like to add Google Analytics to my forum
« Reply #2 on: January 06, 2009, 10:18:05 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

Online vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 20,211
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: I would like to add Google Analytics to my forum
« Reply #3 on: January 06, 2009, 10:25:05 PM »
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

Offline tittiger

  • Semi-Newbie
  • *
  • Posts: 53
Re: I would like to add Google Analytics to my forum
« Reply #4 on: January 06, 2009, 10:32:54 PM »
Thanks that is what I call service.

The Google code should be above.

If you need an email joe@tittiger.com should work.

Or attached here.

Thanks,
Joe

Online vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 20,211
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: I would like to add Google Analytics to my forum
« Reply #5 on: January 07, 2009, 12:28:24 AM »
Fixed file attached
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

Offline sAce

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,992
    • @sbplus_t on Twitter
    • SB+
Re: I would like to add Google Analytics to my forum
« Reply #6 on: January 07, 2009, 12:46:17 AM »
one question ?? what does Google analytics do ?

Offline tittiger

  • Semi-Newbie
  • *
  • Posts: 53
Re: I would like to add Google Analytics to my forum
« Reply #7 on: January 07, 2009, 02:27:19 PM »
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
« Last Edit: January 07, 2009, 03:26:22 PM by tittiger »

Offline tittiger

  • Semi-Newbie
  • *
  • Posts: 53
Re: I would like to add Google Analytics to my forum
« Reply #8 on: January 07, 2009, 05:32:01 PM »
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.   ::)
« Last Edit: January 14, 2009, 04:09:48 AM by tittiger »

Offline tittiger

  • Semi-Newbie
  • *
  • Posts: 53
Re: I would like to add Google Analytics to my forum
« Reply #9 on: January 13, 2009, 06:09:17 AM »
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.
« Last Edit: January 16, 2009, 11:01:57 AM by tittiger »

Offline skyline5k

  • Semi-Newbie
  • *
  • Posts: 14
Re: I would like to add Google Analytics to my forum
« Reply #10 on: January 13, 2009, 08:12:52 PM »
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 [nofollow]." : "http://www [nofollow].");
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.

Offline jay.clark

  • Semi-Newbie
  • *
  • Posts: 96
  • Gender: Male
  • Retired and loving it
    • ExReps - A community for former Tech Reps
Re: I would like to add Google Analytics to my forum
« Reply #11 on: January 16, 2009, 10:50:29 AM »
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 (\)

Code: [Select]
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)

Offline flash_os

  • Semi-Newbie
  • *
  • Posts: 83
Re: I would like to add Google Analytics to my forum
« Reply #12 on: January 23, 2009, 07:27:46 AM »
Thank you, jay.clark!
It's really worked for Google Analytics.
It's simply put before any apostrophe's (') the backslash (\)


Example:

Was: '
Become: \'


Offline STS

  • Semi-Newbie
  • *
  • Posts: 64
  • Gender: Female
Re: I would like to add Google Analytics to my forum
« Reply #13 on: January 28, 2009, 04:27:08 PM »
Worked for me, too. That means it will show up on ALL SMF pages, then?

(thank you!!!)

Offline llckll

  • Semi-Newbie
  • *
  • Posts: 16
Re: I would like to add Google Analytics to my forum
« Reply #14 on: February 25, 2009, 02:57:37 PM »
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.

Offline Joey Smithâ„¢

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,356
  • Gender: Male
Re: I would like to add Google Analytics to my forum
« Reply #15 on: February 26, 2009, 03:12:36 AM »
Well that will depend on which version of smf you are using and which theme.