I can not understand how to add google analytics code in SMF 2.0 gold.

Started by rishab555555, June 18, 2011, 10:23:08 AM

Previous topic - Next topic

rishab555555

I can not understand how to add google analytics code in SMF 2.0 gold. Please tell me in details :(

Suki

Have you tried this mod?

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

if you want to add your code manually then you must modify your theme's Index.template.php   and add your code  between the head tags keep in mind that if you do it manually, you must scape single quotes ' with \   like this \'  to avoid php syntax errors.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

politirant

Why not just add it to index.template.php ?

Is that frowned upon?

mashby

Two other options (in addition to that mod):
1. Edit every index.template.php for any theme you have on your site.
2. Install the Global Headers/Footers mod and use the Headers area to include GA on every theme on your site.
Always be a little kinder than necessary.
- James M. Barrie

BigCheese

I went to the index.template.php file in   Themes/Default Folders and proceeded with this code example:


global $context, $settings, $options, $scripturl, $txt, $modSettings;

// Show right to left and the character set for ease of translating.
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
<head>';
echo "
<script type=\"text/javascript\">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'xx-xxxxxxxx-x']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>";

// The ?fin20 part of this link is just here to make sure browsers don't cache it wrongly.
echo '
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />';




euripides

Quote from: Suki on June 26, 2011, 08:56:11 PM
Have you tried this mod?

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

if you want to add your code manually then you must modify your theme's Index.template.php   and add your code  between the head tags keep in mind that if you do it manually, you must scape single quotes ' with \   like this \'  to avoid php syntax errors.

HI guys.
I just installed this mod. I am using RC3 with anecdota alt. It seems to have been installed, but not sure if it has been installed on the theme, is there anyway to check?

Night09

Quote from: euripides on January 14, 2013, 03:16:53 PM
Quote from: Suki on June 26, 2011, 08:56:11 PM
Have you tried this mod?

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

if you want to add your code manually then you must modify your theme's Index.template.php   and add your code  between the head tags keep in mind that if you do it manually, you must scape single quotes ' with \   like this \'  to avoid php syntax errors.

HI guys.
I just installed this mod. I am using RC3 with anecdota alt. It seems to have been installed, but not sure if it has been installed on the theme, is there anyway to check?


Yes it should be installed and the settings are in the admin > configuration area.  You really should update to the latest version of SMF though.

euripides

Thanks!
is there any way to manually check if it has been installed.
is there a specific place I should be looking for?

Night09

Admin > Configuration > AD Managment >  Add your code in there for google then pick where it should show up.



Sorry having a muddle lol mistook the mod for another.  :P


Advertisement: