Google analytics tracking problem?

Started by imranbutt418, May 27, 2013, 10:36:35 PM

Previous topic - Next topic

imranbutt418

please any one help me how i add my forum site in google analytics tracking i have code but i can't apply becouse i am not now about php plz help me


PHP Implementation optional
Create a PHP file named "analyticstracking.php" with the code above and include it on each PHP template page. Then, add the following line to each template page immediately after the opening <body> tag:
<?php include_once("analyticstracking.php") ?>

this messege is show when i create propery

and my url is thatmobiles.com/forum/index.php [nofollow]

not

this thatmobiles.com/ [nofollow]

if any issue of url so also tell me about it

i am waiting ans

quickly


shadow82x

Where did you get those instructions to add the analytic code? You should just be adding a simple javascript snipet in SMF's index.template.php - https://support.google.com/analytics/answer/1008080?hl=en
Colin B
Former Spammer, Customize, & Support Team Member

imranbutt418

#2
i am adding tracking code who give my google accoun but not working

see attachments code and error please


shadow82x

There's a few things I see wrong with that code. Mind attaching your index.template.php here? We can fix it up for you.
Colin B
Former Spammer, Customize, & Support Team Member

imranbutt418


imranbutt418

shadow82x please do some thing im very thankful to you i am waiting your reply

imranbutt418


mashby

Always be a little kinder than necessary.
- James M. Barrie

Sybille Yates


TheListener

@Sybille yes.

Please read the Mod Emulate link in my signature.

;)

Sybille Yates

Quote from: Old Fossil on May 31, 2013, 02:46:18 PM
@Sybille yes.

Please read the Mod Emulate link in my signature.

;)

Purrrfect! Worked a treat, thanks ever so much! SY

Uncle Buck

I know this is an old topic but the solution given was for use with the original ga.js rather than the new analytics.js even though the user was referring to the new js code.
Google intends to support the old ga.js for a further two years but to get the most from analytics, you need to use the new code.

This is what the mod suggested inserts into the file Subs.php....
// Google Analytics Integration
function ob_google_analytics($buffer)
{
global $modSettings;

if (!empty($modSettings['googleAnalyticsCode']) && !isset($_REQUEST['xml'])) {
$google_code = '
<script type="text/javascript"><!-- // -->' . chr(60) . '![CDATA[' . '
var _gaq = _gaq || [];
_gaq.push([\'_setAccount\', \'' . $modSettings['googleAnalyticsCode'] . '\']);
_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);
})();
// ]]' . chr(62) . '</script>';

// add in the analytics code at the very end of the head section
$buffer = substr_replace($buffer, $google_code . "\n" . '</head>', stripos($buffer, '</head>'), 7);
}

// All done
return $buffer;
}


But the new code as shown early in the thread is as follows.....
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-xxxxxxxx', 'yoursite.com');
  ga('send', 'pageview');

</script>


I am not a programmer so I hope someone will be able to advise how the new code needs to be formatted to work correctly.

mashby

<script>
  (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');

  ga(\'create\', \'UA-xxxxxxxx\', \'yoursite.com\');
  ga(\'send\', \'pageview\');

</script>
Of course, changing the UA-xxxxxxx part.
Always be a little kinder than necessary.
- James M. Barrie

Uncle Buck

Thanks for that.... This was the final replacement code that I had to use so that it picked up the UA code from the database:

function ob_google_analytics($buffer)
{
global $modSettings;

if (!empty($modSettings['googleAnalyticsCode']) && !isset($_REQUEST['xml'])) {
$google_code = '
<script type="text/javascript"><!-- // -->' . chr(60) . '![CDATA[' . '
(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');

  ga(\'create\', \'' . $modSettings['googleAnalyticsCode'] . '\', \'mysitename.com\');
  ga(\'send\', \'pageview\');
// ]]' . chr(62) . '</script>';

// add in the analytics code at the very end of the head section
$buffer = substr_replace($buffer, $google_code . "\n" . '</head>', stripos($buffer, '</head>'), 7);
}

// All done
return $buffer;
}


Advertisement: