Google Analytics Code

Started by SMF Customization Team, October 15, 2009, 12:10:12 PM

Previous topic - Next topic

Shambles

Sources/Subs.php


Code (Locate) Select

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



Code (Replace with) Select

$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'].'\', \'auto\');
ga(\'send\', \'pageview\');

// ]]' . chr(62) . '</script>';

Suki

Quote from: ormuz on November 28, 2017, 05:26:39 AM
I suspect that there was an analytics code update. The tracker isn't working itself.

What version of the mod are you using?

version 1.5.1 uses the correct Universal Analytics code.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

ormuz

Quote from: Suki on November 29, 2017, 12:02:18 PM
Quote from: ormuz on November 28, 2017, 05:26:39 AM
I suspect that there was an analytics code update. The tracker isn't working itself.

What version of the mod are you using?

version 1.5.1 uses the correct Universal Analytics code.

I'm using 1.5.1

This is what google analytics tells me to use
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'ID');
</script>


This is what version 1.5.1 looks like
<script type="text/javascript">
(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'] . '\', \'' . $_SERVER['SERVER_NAME'] . '\');
ga(\'send\', \'pageview\');
</script>';


ormuz

Although official docs looks otherwise... and the mod snippet looks more than correct
https://developers.google.com/analytics/devguides/collection/upgrade/reference/gajs-analyticsjs

I'm confused now :D

Suki

It seems the code you are trying to implement belongs to a different, somehow related to analytics tracking system.  As far as I can see in google analytics docs, the code in 1.5.1 is still supported.

If you want to use the other code then you will need to implement a different mod or modify this one to suit your needs.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

FNetV1

I just added the Google Analytics plugin to my SMF version 2.0.8 forum.  I downloaded the plugin from:
http://custom.simplemachines.org/mods/index.php?mod=2210
"GoogleAnalysics.zip" and its version 1.5.1 which appears to be the latest version.

Then I logged into my hxxp:analytics.google.com [nonactive] account, I added the new property (my website namen and URL) and then I retrieved the code to add to the plugin, my code was: UA-UA-xxxxxxxx-4 (where "xxxxxxxx" that was added by me here to conceal the numbers that are originally there represents a string of 8 numbers).  After this I saved it.

Next: I simulated two traffic counts/hits, by first going to my website from my own computer, and then I RDP'd to my computer that is logged into my VPN with a foreign IP addrses to simulate another unique real visitor, after that I logged in back to my hxxp:analytics.google.com [nonactive] account, and was shown a total of 0 hits and 0 traffic to my website.

Did I miss anything?  It seems like google analytics isn't piking up the hits despite me having installed the plug-in and having added the correct code under the Miscenalleous section.  Does it take time for Google Analytics to start counting hits?

Thanks.

Kindred

Typically google is a day or so behind.

Btw, you NEED to update your site. You are 7 versions behind, including multiple security updates.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

FNetV1

Quote from: Kindred on August 18, 2018, 09:28:11 PM
Typically google is a day or so behind.

Btw, you NEED to update your site. You are 7 versions behind, including multiple security updates.
I though I was running the very latest version of SMF because just today I was presented with :
SMF 2.0.8 Update
when I finished checking out the Package Manager for the very first time.  I installed it.  Before I was on 2.0.7

I installed SMF on my site on July 2, 2018 using cPanel's once click script installer, everything was configured for me automatically and I had a working forum in less than one minute.  I could have done it manually, seting correct CHMOD persmissions, uploading SQL to MySQL, setting up sql user and passwords and all what, but I am glad that all that was taken care for me in less than 1 minute, I remember back in the days how long it used to take me to manually properly install and configure a PHP script with SQL database.

Well anways, my question to you would pertain in 7 versions behind my site is running.  Since I installed SMF from cPanel's one click installer, isn't it the responsibility of my web hosting provider to ensure my script is always up to date?  My web hosting provider is Hostgator, I am under a reseller account with limited admin rights (I don't have a web server all to myserlf with full ROOT access), so I would guess when hostgator decides to update the version of SMF that they have in store in their webserver for the one click install that then my version gets updated at that point automatically.  If I am right then this would mean that I always will be a few versions behind. 

Am I right on my assumption?  If my site doesn't get updated autmatically then how can I update it manually, considering the fact that I dont even have the user name and password of the MySQL database as that was also automatically generated by the cPanel's one click script installer.  All I have is just the password for my SMF admin interface.

May I ask what's the latest version as of this moment?

Kindred

The largest version is 2.0.15

We never suggest using a host autoinstaller because of the exact reason that you list. You don't know the information about the install and don't necessarily have control over the system.

However,  you should be able to update using the patches, from version to version in the package manager just like you did for the 2.0.7 to 2.0.8 update.

Add four your database details... look in the settings.php file...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Shambles

QuoteUA-UA-xxxxxxxx-4

That doesn't look right... all of mine only have the one occurrence of the UA- prefix.

Kindred

oops... I missed that.

Yeah, that's also going to stop google from indexing...   
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Diego Andrés

1.6 - 21 March 2022
- SMF 2.1 release
+ Now using newer gtag code

SMF Tricks - Free & Premium Responsive Themes for SMF.

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Diego Andrés

1.6.1 - 25  January 2023
! Remove extra space in the code id

Thanks to @dga for reporting.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Ricsca


Diego Andrés

Naming conventions on this became confusing.
This is using GTAG afaik, which includes GA4 (supposedly).

SMF Tricks - Free & Premium Responsive Themes for SMF.

gorbi

Do this mod work with google analytics 4?

Advertisement: