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.
Related
So on all my web pages i have this code what is used by Yandex metrika for analytics. According to google this script is slowing down my pages and needs something changing in the way it loads to not be render blocking, TTI time to input blocking, FID first input delay blocking, First contentful paint blocking.
<script data-cfasync="false" type="text/javascript">
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym(XXXXXXXX, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
});
</script>
Googles page speed reports the following
https://developers.google.com/speed/pagespeed/insights/
What can i modify the Yandex metrika javascript to in order to fix this issue ?
You don't have many options I am afraid as it is a third party script.
One option to improve your score and perceived load times is to wrap the call to the function in a setTimeout set long enough to delay loading the script until the essential content is loaded.
<script data-cfasync="false" type="text/javascript">
setTimeout(function(){
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym(XXXXXXXX, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
});
}, 5000); //set this as high as you can without ruining your stats.
</script>
This is definitely a workaround and I would instead advise using a different library that is less bloated if you can find one.
<script data-cfasync="false" type="text/javascript">
(function(){
var a = function() {try{return !!window.addEventListener} catch(e) {return !1} },
b = function(b, c) {a() ? document.addEventListener("load", b, c) : document.attachEvent("onreadystatechange", b)};
b(function(){
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym(XXXXXXXX, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
});
}, false);
})();
</script>
One option is to use old Yandex Metrika code (new Ya.Metrika...).
You can view the old code if you set checkbox in advanced settings of the Metrika. Old code has some limitation but it's much smaller and few times faster.
Disabling clickmap and webvisor could help.
As the documentation says:
There is a debugging version of Google Analytics that will print extra info to the console for debugging purpouses. However, this version will send data to GA even when it is only for debugging.
According to this documentation (that is a bit outdated), we need to add this code to our Google Analytics code to avoid sending hits to GA:
if (location.hostname == 'localhost') {
ga('set', 'sendHitTask', null);
}
However, I'm using a newer version of GA that uses gtag in the tracking code, So I've change the ga function to gtag:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-134628373-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-134628373-1');
if (location.hostname == 'localhost') {
gtag('set', 'sendHitTask', null);
}
</script>
Just for clarification:
if (location.hostname == 'localhost') {
ga('set', 'sendHitTask', null);
}
to:
if (location.hostname == 'localhost') {
gtag('set', 'sendHitTask', null);
}
Is this the correct approache? I don't want to mess my data.
I'm using GTM to deploy the GA code. In order to make the changes to the GA tracking code, I've used a Custom HTML Tag.
There is a slightly different implementation for gtag. You can set the following window property to true in the conditional statement:
window['ga-disable-GA_MEASUREMENT_ID'] = true;
Replace GA_MEASUREMENT_ID with the Analytics ID of the property that you would like to disable.
This window property must be set before any calls to gtag() are made, and it must be set on each page for which you want to disable Analytics. If the property is not set or set to false, then Analytics will work as usual.
More info in link below. Hope it helps.
gtag ga-diasble setting
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.
I've created a google content experiment without redirects using the docs.
The basic implementation involves a javascript snippet that uses the following code to choose the version of the experiment:
<!-- Load the Content Experiment JavaScript API client for the experiment -->
<script src="//www.google-analytics.com/cx/api.js?experiment=YOUR_EXPERIMENT_ID"></script>
<script>
// Ask Google Analytics which variation to show the user.
var chosenVariation = cxApi.chooseVariation();
</script>
<!-- Load the JQuery library -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
// Define JavaScript for each page variation of this experiment.
var pageVariations = [
function() {}, // Original: Do nothing. This will render the default HTML.
function() { // Variation 1: Banner Image
document.getElementById('banner').src = 'bay-bridge.jpg';
},
function() { // Variation 2: Sub-heading Text
document.getElementById('heading').innerHTML = 'Look, a Bridge!';
},
function() { // Variation 3: Button Text
document.getElementById('button').innerHTML = 'Learn more';
},
function() { // Variation 4: Button Color
document.getElementById('button').className = 'button button-blue';
}
];
// Wait for the DOM to load, then execute the view for the chosen variation.
$(document).ready(
// Execute the chosen view
pageVariations[chosenVariation]
);
</script>
However, when I visit the page using an incognito window, I only see the first variation of the experiment. When I check chosenVariation in the console, it's always 0. In fact, when I call cxApi.chooseVariation(); in the console, it always returns 0.
Is this because google recognizes my incognito browser windows, or is something broken with cxApi.chooseVariation(); or in my implementation?
I had the same problem, 100% of the sessions were given the original (0) variation. In order to fix the problem, I added the javascript code provided by the experiment. Go to your experiment (edit), click Setting up your experiment code, manually insert the code, copy the code in there.
Now since you (and I) don't want to have a redirect, remove this part at the end of the code <script>utmx('url','A/B');</script>. If your page is templated, you can use a variable and insert your experiment key (not experiment id) where you see var k='########-#'
Now either very few people use the experiments in a client-only fashion or we're totally stupid because it would seem to me that the guide is wrong and there's absolutely no documentation that shows a working client-only setup.
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']);