xoops forums

xd9527

Just popping in
Posted on: 1/31 9:21
xd9527
xd9527 (Show more)
Just popping in
Posts: 4
Since: 2016/1/13
#1

Track Xoops user detail in Google Analytics

Step1. Enables GA User-ID
https://support.google.com/analytics/answer/3123662

Step2. Add Track code in your xoops template
use new track code (gtag.js)
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_UAID"></script>
<{if 
$xoops_isuser}>
<
script>
window.dataLayer window.dataLayer || [];
function 
gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config''GA_TRACKING_UAID', { 'user_id''<{$xoops_name}>' });
</
script>
<{else}>
<
script>
window.dataLayer window.dataLayer || [];
function 
gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config''GA_TRACKING_UAID', { 'user_id''<{$smarty.const._GUESTS}>' });
</
script><{/if}>


if use old code (analytics.js)
<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''GA_TRACKING_UAID''YOUR_DOMAIN_NAME');
<{if 
$xoops_isuser}>
var 
xoopsuser_name "<{$xoops_name}>";
ga('set''userId'xoopsuser_name );
<{/if}>
ga('send''pageview');
</
script>


Clear Template Cache
now you can track your xoops user log detail in Google Analytics

reference
https://developers.google.com/analytic ... llection/gtagjs/migration
https://developers.google.com/analytic ... on/gtagjs/cookies-user-id
https://developers.google.com/analytic ... ion/gtagjs/setting-values

Resized Image
Resized Image

thanks , i'm come from taiwan. (not china)
my english very pool , so embarrassed

My Blog
https://3q.9527.tw/103

Mamba

Moderator
Posted on: 2/2 8:26
Mamba
Mamba (Show more)
Moderator
Posts: 10559
Since: 2004/4/23
#2

Re: Track Xoops user detail in Google Analytics

Thanks for sharing!

And you English is fine, so don't worry about it!
Support XOOPS => DONATE
Use 2.5.9 | Docs | Modules | Bugs

xd9527

Just popping in
Posted on: 2/5 1:49
xd9527
xd9527 (Show more)
Just popping in
Posts: 4
Since: 2016/1/13
#3

Re: Track Xoops user detail in Google Analytics

thank you Mamba
can add GA code in system maybe next xoops vertion
like wordpress have this function