News:

Wondering if this will always be free?  See why free is better.

Main Menu

Google Analytics specific solution for SMF

Started by Briankbc, December 28, 2008, 05:02:20 PM

Previous topic - Next topic

Briankbc

Hi

The Google Analytics solution question comes up all the time. There are so many messages about it.

So I wrote a blog post with the solution.

Actually, it gave me the idea for the blog itself, called Analytix Specifix.

The code and the solution are at:
Simple Machines Forum Software and Google Analytics [nofollow]

I have not used it on 2.x but it should work in exactly the same way.

Please leave feedback there in the blog comments.

Brian Katz
Google Analytics Consultant

vbgamer45

Any reason for using the require instead of just including the javascript code in the template?
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

glennk

#2
Having recently had this problem I think inserting the code into the template causes an error. I will be watching your answers with interest

vbgamer45

It would only cause an error if you do not escape the javascript properly.
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

glennk


aldo

Why do you need a "specific" solution..? All you need is to be sure to escape the ' in the code and paste it... O.o

H

#6
Quote from: aldo on December 30, 2008, 02:40:29 AM
Why do you need a "specific" solution..? All you need is to be sure to escape the ' in the code and paste it... O.o

Indeed it makes sense to just hardcode it in the index template :).

If people would rather not mess with code, then they can use the ad mod

/edit: grammar
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

glennk

At the risk of sounding really thick. How do you escape the code and can someone give me something to copy and paste and tell me where to put it in the template. Obviously I will add my own tracking code number.

Kermit

Escaping single quotes means that

eg.

without escape


<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-#######-#");
pageTracker._trackPageview();
} catch(err) {}</script>


with escape

<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-#######-#");
pageTracker._trackPageview();
} catch(err) {}</script>


I hope,it's clear now,what escaping means

After escaping you should put your code in index.template.php and right there

Code (find) Select

</body>


and add before your analytics code
My Mods
Please don't PM/mail me for support,unless i invite you
Formerly known as Duncan85
Quote
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

A. Einstein

glennk

Thanks Duncan

As a non programmer its difficult to understand sometimes. By looks of it, it is a matter of sticking a \ in front of every '  ?? Not sure what the reasoning is but ill just copy and paste yours and add the right code.

Best wishes - Glenn

vbgamer45

The reason is SMF displays everything using the echo statement which uses '

echo 'Hello World';
[code]

If you add an extra ' such as in the following it will break the code
[code]
echo 'Hello World's';
[code]
Since PHP will read that line and see an opening and closing ' but then there is extra s' afterwords to fix you just escape it

[code]
echo 'Hello World\'s';
[code]
Now this works since you are escaping the extra '
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

KahneFan

The easiest way I've found for this is to use the Global Headers and Footers mod...

http://custom.simplemachines.org/mods/index.php?mod=351

And simply insert the code into your global footer.
#eric_on_twit| (video) Creating Themes for SMF | Reset Your Forum
NOTE: No PM's for support please.

spaceboy

Thanks Duncan85, that worked perfectly.  Thanks for showing exactly what to do.  I freaked out when I got the error and frantically reloaded the original index.template.

Thanks again!

Advertisement: