News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

is there any way to add google analytics on a forum?

Started by ThePro, October 10, 2008, 05:17:51 PM

Previous topic - Next topic

ThePro

I want to know if its possible to add google analytics to a smf 2.0 site

Adish - (F.L.A.M.E.R)

I suppose, you have to make an html file, give it a permission to read/write and execute (bascially chmod 777) and then add the site in google analytics and they will analyze it. Is that what you want ?

Rumbaar

Can I ask how you add it to a 1.1.x forum?  As I'm quite sure the process for that is the same as 2.x, and I know people do it for both I'm sure.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

Kermit

$themedir/index.template.php



Code (find) Select

</body>


Code (add before) Select

<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">
var pageTracker = _gat._getTracker("UA-2576254-5");
pageTracker._initData();
pageTracker._trackPageview();
</script>


for sure,you should replace the codes above with your own analytics code
  :P
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

Rumbaar

So nothing really special from 1.1.x or 2.x template files.  Just same ol' HTML/javascript.

Thank you Duncan85.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

metaphysic

Quote from: Duncan85 on October 22, 2008, 05:26:16 AM
$themedir/index.template.php



Code (find) Select

</body>


Code (add before) Select

<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">
var pageTracker = _gat._getTracker("UA-2576254-5");
pageTracker._initData();
pageTracker._trackPageview();
</script>


for sure,you should replace the codes above with your own analytics code
  :P

i do it but have a error

Template Parse Error!
It seems something has gone sour on the forum with the template system. This problem should only be temporary, so please come back later and try again. If you continue to see this message, please contact the administrator.

You can also try refreshing this page.

greyknight17

Attach your index.template.php file here with the modifications you made.

Rumbaar

Yes, that exact code put into the position just before the </body> text in your index.template.php shouldn't return a parse error.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

metaphysic

   echo '
         </div>
       </div>
       </div>
      </div>';

   // 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>';

echo '


</body></html>';
}



// Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
function theme_linktree()
{
===================

this is part of index.template.php where i should put analytics code

greyknight17

Quoteecho '

<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">
var pageTracker = _gat._getTracker("UA-2576254-5");
pageTracker._initData();
pageTracker._trackPageview();
</script>



</body></html>';

metaphysic



// 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>';


echo '

<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">
var pageTracker = _gat._getTracker("UA-2199007-29");
pageTracker._trackPageview();
</script>

</body></html>';
}



// Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
function theme_linktree()
{



and dont work, i have no idea

Kermit

try this

<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">
var pageTracker = _gat._getTracker("UA-2199007-29");
pageTracker._trackPageview();
</script>
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

metaphysic


Kermit

the important php rule

single quotes ' should be replaced with \'   ;)
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

nyfalcon

Thanks for the help. As a newbie to php I didn't know that rule and didn't realize I had to change a few ' to \' what is there 3 or 4 in the code
hxxp:my-sports-merchandise.com/smf/index.php [nonactive]

Briankbc

#15
Hi

There are so many posts on this forum relating to this question that 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 of comments:
Simple Machines Forum Software and Google Analytics [nofollow]


Brian

Briankbc

Check out this message:
http://www.simplemachines.org/community/index.php?topic=282817.msg1856304#msg1856304

of go directly to the code and the answer at:

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

Advertisement: