I'm using angulartics to track a single web app. Angulartics documentation says that in order to work properly I need to comment automatic tracking lines and I quote:
"Make sure you delete any automatic tracking line from your vendor snippet code!"
// Google Analytics example
ga('send', 'pageview'); // <---- delete this line!
Since I'm using piwik I'll attach the snipet of code that they provide:
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
(function(){ var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/");
_paq.push(['setSiteId', {$IDSITE}]);
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
s.parentNode.insertBefore(g,s); })();
</script>
<!-- End Piwik Code -->
My question here is, what lines should I comment?
The following ...
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
?
Thanks for the help
Piwik uses following line to start tracking page views:
_paq.push(['trackPageView']);
Related
I need some help with google analytics, gtag and gtm scripts
This is how I am generating the partytown snippet in webpack ->
const snippetText = partytownSnippet({
debug: config.env !== 'production',
forward: [
'dataLayer.push',
'GoogleAnalyticsObject',
'ga',
'gtag'
],
resolveUrl: (url, _location, type) => {
const proxyScriptHosts = [
'www.google-analytics.com',
'www.googletagmanager.com',
];
if (type === 'script' && !!url && proxyScriptHosts.find((proxyScriptHost) => url.host.includes(proxyScriptHost))) {
const proxyUrl = new URL('https://my-proxy.com/api/proxy');
proxyUrl.searchParams.append('url', url.href);
return proxyUrl;
}
return url;
}
});
Then I insert this snippet in my index.html file like this -
<script type="text/javascript">{snippetText}</script>
Now I need to load 3 scripts for my app, this is where I need help to understand what I am doing wrong -
this is how I am loading the google analytics script -
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
window.gtag = function () {
window.dataLayer.push(arguments);
}
window.GoogleAnalyticsObject = 'ga';
window.ga = function () {
window.ga.q = window.ga.q || [];
window.ga.q.push(arguments);
};
window.ga.l = 1 * new Date();
</script>
<script type="text/partytown" async defer fetchpriority="low" src="https://www.google-analytics.com/analytics.js"></script>
in one of my react components, i am initializing google analytics like this ->
window.gtag('js', new Date());
window.gtag('config', gaId, options);
This works perfectly fine, i can see google analytics UA4 requests in the network tab working as expected!!
2. this is how i am loading the gtag script -
<script type="text/partytown" async defer fetchpriority="low" src="https://www.googletagmanager.com/gtag/js?id=${gtagId}"></script>
this is how i am loading the gtm script -
<script type="text/partytown" async defer fetchpriority="low" src="https://www.googletagmanager.com/gtm.js?id=${gtmId}"></script>
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
</script>
Gtag and GTM scripts aren't working, none of the events are being sent for them, please help me understand. I need ga, gtag, and gtm all 3 in my case working together
Please help me with this, i've been stuck on it for quite some time, need to understand the right way to do this
I have searched in the official partytown docs and read various blogs online, this is as far as I've gotten
oo very interesting, this is my advice: To get gtag and GTM working, you need to make sure the following things:
You have created a gtag tracking code in your Google Analytics account and have added the tracking ID in your code: (reCheck)
'<'script type="text/partytown" async defer fetchpriority="low"
src="https://www.googletagmanager.com/gtag/js?id=${gtagId}"></script'>'
You have created a GTM container in your Google Tag Manager account and have added the container ID in your code: (reCheck)
<script type="text/partytown" async defer fetchpriority="low" src="https://www.googletagmanager.com/gtm.js?id=${gtmId}"></script>
Make sure the data layer is correctly initialized before the GTM script is executed:
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
</script>
Verify that your GTM container is configured to fire the gtag tracking code, which will send the data to Google Analytics.
If you have done all the above steps correctly, and still the events are not being sent, try checking the network tab in the browser's developer tools to see if there are any errors being returned for the gtag or GTM requests. If there are errors, fix them, and try again.
This is turning out to be much more challenging than I expected.
There is a Google Analytics Integration extension:
https://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration
But for the Global Site Tag version of Google Analytics, it refers you to the HeadScript extension:
https://www.mediawiki.org/wiki/Extension:HeadScript
The problem here is the download link (http://downloads.jingames.net/mediawiki/HeadScript.zip) looks a bit dodgy and the documentation mentions a bug.
I've also reviewed this discussion on the Mediawiki site:
How can I add the code into the <head>?
But it's a lot of telling and not much showing.
The Google Analytics snippet looks like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TRACKING_ID');
</script>
I would prefer to insert it by updating a setting in LocalSettings.php config file.
Thanks!
I found a way to insert the tag into LocalSettings.php using the $wgHooks setting as demonstrated here:
https://www.mediawiki.org/wiki/Topic:Uxv32na6lh6wd5rf
Just replace TRACKING_ID (in both spots) with your Analytics tracking ID and paste this at the bottom of LocalSettings.php:
$wgHooks['BeforePageDisplay'][] = function( OutputPage &$out, Skin &$skin ) {
$code = <<<HTML
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TRACKING_ID');
</script>
HTML;
$out->addHeadItem( 'gtag-insert', $code );
return true;
};
This is a very old post but for anyone else who might happen upon this I have found a possible solution by combining other examples.
I have used Tom's code as an example and replace the corresponding variables within the google analytics extension.
Change the hook in googleAnalytics.hooks.php line 9.
Old:
...
public static function onSkinAfterBottomScripts( Skin $skin, &$text = '' ) {
...
New:
...
public static function onBeforePageDisplay( OutputPage &$out, Skin $skin ) {
...
Then replace all mentions of $text with $code, there are 5 of them on lines, 14, 24, 31, 54, and 59.
Then at the end of the parser function above the return true; insert the following code on line 61.
$out->addHeadItem( 'gtag-insert', $code );
Finally go into googleAnalytics.php line 52 (Bottom of file) and replace the hook call to use the new hook.
Old:
...
$wgHooks['SkinAfterBottomScripts'][] = 'GoogleAnalyticsHooks::onSkinAfterBottomScripts';
...
New:
...
$wgHooks['BeforePageDisplay'][] = 'GoogleAnalyticsHooks::onBeforePageDisplay';
...
If everything worked out you will see the googleAnalytics extension script in the head element as opposed to within the body. I am going to try and contact the creator/contributors of the extension and see if it can be change or ask why its not this way already.
There is a google analytics extension.
Alternatively, the script can be added to Mediawiki:Common.js using document.write to link to the url and your site's UA-xxxxxx-x:
// GOOGLE ANALYTICS (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-xxxxxx-x', 'auto'); ga('send', 'pageview');
// END GOOGLE ANALYTICS
I am currently working on a website with existing Auto Ads with the following code block:
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-XXXXX",
enable_page_level_ads: true
});
</script>
and few ads with the same code as below:
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<script>
googletag.cmd.push(function() {
googletag.defineSlot('/XXXXX/Desktop_Header', [
[970, 250],
[970, 90],
[728, 90]
], 'div-gpt-ad-XXXXXX-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
Given that, I am having the following issue in the dev tool console.
adsbygoogle.push() error: Only one 'enable_page_level_ads' allowed per
page.
That error disappears when the former script block was deleted but as far as I understand Auto Ads can co-exist with other ads. Up until now, I cannot find a specific solution even from the Google forum itself.
...because you appear to have multiple page-level ad codes in your site.
You only need one.
I just faced the same error few days back, my problem is that I had multiple adsbygoogle = window.adsbygoogle || []).push in a code because on master, child and sometimes partial page.
I was recently having the same problem, and when I into my code, I had added one set of google ads code in the header while coding the page and another I had added using the plugin. I removed it from my plugin. It worked for me.
I am trying to get statistics about sign ups on my website.
The analytics code is in the header:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=...."></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', '....');
</script>
Then I have a form and sending it (with a page reload, not ajax) and in the success snippet in razor I placed the ga code:
#if (success)
{
<script type="text/javascript">
ga('send', 'event', 'Supplier sign up', 'click', '/signup/success');
</script>
<p>success message</p>
}
The success message appears and I can see the script in the page inspect but I don't get any stats in Google Analytics.
Am I missing something? In the past (a few years ago) I was using a similar code and it worked. Has anything changed recently? Do I need to enable something in the Analytics or my code is wrong?
I am following the documentation:
https://developers.google.com/analytics/devguides/collection/analyticsjs/events
https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
The implementation method for your GA is through gtag.s, not GTM or analytics.js.
Thus you need to modify your success to:
#if (success)
{
<script type="text/javascript">
gtag('event', 'click', {'event_category': 'Supplier sign up', 'event_label': '/signup/success'});
</script>
<p>success message</p>
}
You have mixed two GA libraries. You use gtag.js for page view, so you need to use gtag.js (not analytics.js) for events.
https://developers.google.com/analytics/devguides/collection/gtagjs/events
Some days ago I introduced the new gtag version of Google Analytics to my private website. Now I try to figure how to filter out my own traffic. Exclusion based on IP is not possible because I enter my website with different browsers from different places. So I wanted to exclude my traffic via cookie. I'm just not able to make it work. The documentation is telling I should work now with dimensions. I tried it but it is not working for me.
I set up a dimension "usertype"
and I added a filter to exclude pattern "internal" for dimension "usertype"
I created a new page for my website and put the following code
<html>
<head>
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-XX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-XXXXXXX-XX', {'custom_map': {'dimension1': 'usertype'}});
gtag('event', 'kill_ga', {'usertype': 'internal'});
</script>
<!-- Google Analytics -->
<meta http-equiv="refresh" content="5; url=/" />
</head>
<body>
We'll transfer you soon
</body>
</html>
As I said before. I'd like to somehow mark my own traffic as internal and exclude it via filter.
Could someone help me to achieve this please?
There are many approaches to blocking your own traffic, I think using the usertype is one approach. Historically, I've solved it with a simple cookie check:
You'd ask any developer/tester to create a cookie on your site by 1) visiting your site, then 2) entering something like this into their browser's JS console:
Set the persistent cookie, "prevent_ga" equal to true
document.cookie = "prevent_ga=1"
Then check the cookie before invoking GA on your site:
var check_cookie = document.cookie.match(/^(.*;)?\s*prevent_ga\s*=\s*[^;]+(.*)?$/)
if (!check_cookie) {
// do gtag() things
}
I used it finally in a completely different approach.
As you can see on https://www.smest.it I solved with JavaScript directly on my page.
In footer of any page:
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script>
var gaProperty = 'XXXXXXX-XX';
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
}
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-XX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){
dataLayer.push(arguments)
}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXX-XX', { 'anonymize_ip': true });
</script>
In my privacy policies, I have the following link.
<a onclick="alert('Google Analytics is now deactivated');" href="javascript:gaOptout()">Deactivate Google Analytics</a>
This will turn off analytics completely.