News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Any way to use Google Analytics with SMF

Started by ekfaysal, August 23, 2008, 07:04:00 AM

Previous topic - Next topic

ekfaysal

As question says is there Any way to use Google Analytics  with SMF?

NickC

Put the Google Analytics code immediately before the </body> tag in index.template.php. If you allow members to choose themes, put it in all of them. Have a look at the source on my forum.

Rumbaar

Looking at your forums page source it appears you've been able to do this?

If this is solved feel free to mark it as solved otherwise reply with some details of what isn't working.  To mark an issue solved please change the first post message icon to the 'tick' icon.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

hw610

I have Analytics on my board and all i did was install the Ad Management Mod and create a "Footer" ad to put my footer on the board and put the Analytics code in there.  Works fine for me. :)
**Thanks for all the help but we have moved to vB.

Briankbc

#4
Hi

With so many posts on this forum asking this question I created a blog post for it - in fact it inspired the entire blog.

Here's the solution - please try it out and give me feedback by way of comments:
Simple Machines Forum Software and Google Analytics [nofollow]


Brian

ifwmonster

I know this post is kind of old, but it may still be helpful.

Here is how I solved it on SMF 1.1.8

echo '
<div id="ajax_in_progress" style="display: none;', $context['browser']['is_ie'] && !$context['browser']['is_ie7'] ? 'position: absolute;' : '', '">', $txt['ajax_in_progress'], '</div>'
//Begin Google Analytics
        ?><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><?php echo '
</body></html>'
;


I just added a single quote at the end of the first line, closed out PHP, inserted Google Analytics code, reopened php and continued the echo.  Make sure to replace the # signs towards the end with your UA string.

piju2111

 great thanks'

Anybody who still don't understand or unable to successfully deploy check on this
hxxp:www.acquirepc.com/forum/index.php/topic,55.msg67.html#msg67 [nonactive]

sim19

what is wrong ( parse error )

window_oldOnload = null;
            }
                        }';
                }

                echo '
      // ]]></script>';
        }
echo '</div>';   echo '
       



    ?><script type="text/javascript">
var gaJsHost = (("hxxps:" == document.location.protocol) ? "hxxps://ssl." : "hxxp://xxx.");
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-xxxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}</script><?php echo '

</body>
</html>';

Senkusha

Quote from: sim19 on March 18, 2010, 01:11:48 PM
what is wrong ( parse error )

window_oldOnload = null;
            }
                        }';
                }

                echo '
      // ]]></script>';
        }
echo '</div>';   echo '
       



    ?><script type="text/javascript">
var gaJsHost = (("hxxps:" == document.location.protocol) ? "hxxps://ssl." : "hxxp://xxx.");
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-xxxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}</script><?php echo '

</body>
</html>';


I've highlighted somethings to try, things that might be your issue.  I had to escape the single quotes when I added mine in as well, works perfect for me.  Oh, and the first bolded line, I'm not sure what's going on there, but it looks like your missing a semicolon at the end of the statement (note the one that is there is commented out in the next line).
--Senkusha
The Anime Brigade
Anime-style Role Playing Games and Discussion.
(SMF v. 2.1.4, PHP v. 8.0)

Joker™

Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

sim19

Thanks for your help
Tema is mercury11rc1
This is original index.template.php

}

            if (window_oldOnload)
            {
               window_oldOnload();
               window_oldOnload = null;
            }
                        }';
                }

                echo '
      // ]]></script>';
        }
echo '</div>';
        echo '

        </body>
</html>';
}



dan3

Quote from: ifwmonster on March 07, 2009, 12:42:36 PM
I know this post is kind of old, but it may still be helpful.

Here is how I solved it on SMF 1.1.8

echo '
<div id="ajax_in_progress" style="display: none;', $context['browser']['is_ie'] && !$context['browser']['is_ie7'] ? 'position: absolute;' : '', '">', $txt['ajax_in_progress'], '</div>'
//Begin Google Analytics
        ?><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><?php echo '
</body></html>'
;


I just added a single quote at the end of the first line, closed out PHP, inserted Google Analytics code, reopened php and continued the echo.  Make sure to replace the # signs towards the end with your UA string.
I tried using this code but I get this error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in index.template.php on line 352
which looks like its in this line: $txt['ajax_in_progress'], '</div>'

Any suggestions?

agguvenligi

Quote from: Joker™ on March 18, 2010, 02:13:01 PM
http://custom.simplemachines.org/mods/index.php?mod=2210

more easy way ;)

This not working i have logged in my forum 2-3 times but i cannot see on google analystic code have you a idea what is problem ?
Gerçeği aramak onu bulmaktan daha kıymetlidir...
____________________________________
Dodge Check Engine Light | Yeni Private Serverlar | Gsm Destek

Advertisement: