ad and content blocker from your own domain
poor justification To use server-side GTM.user’s wish Blocking a script will be disregarded and forcibly download the script that you wanted to avoid downloading in the first place.
Because it is on the server side, you may want to use it to avoid, tracking, and consenting browser blocklists.
はい、これをすべて行うことができます。しかし、あなたはディックである必要はありません。 Always error on the largest side.ユーザーのプライバシーを尊重します。 5/6
— Simo Ahava (@SimoAhava) January 29, 2020
However, this is not another article that laments this disconnection between a hungry analyst with the data and a site visitor who has no doubt.
To avoid using it instead detection.
Ad blockers and content blockers are a given, but I think it’s absolutely critical to measure their impact.こうすることで、これらのツールが原因でブロックされた分析および広告リクエストの数を計算できます。
When
X
shimmer newsletter
this is proof of concept. ここで示しているのは、検出システムを作成するために必要なコンポーネントの一部ですが、ほとんどの作業はクライアント側 (検出が行われる場所) で行う必要があるため、これらのアイデアを調整and what your
This article will show you how to measure three things:
- View rate of homepage advertisement blocked.
- google analytics blocked.
- View rate of homepage Google Tag Manager blocked.
Server-side tagging
i use custom client template bait file So are the pixels used to generate the event data object.
A decoy file contains instructions for the browser to generate an element with an ID. GxsCRdhiJi
This is the element you should look for to see if the file has been blocked.
Most of the magic has to be done on the client side.
In my site’s page template, I run the following script in the page HTML: Yes, this should be done outside of Google Tag Her Manager. Because if GTM is blocked, client-side scripts are also blocked, so the impact cannot be measured.
(function() {
// Set these to the endpoints configured in the Client template
var baitPath = 'https://sgtm.simoahava.com/ads-min.js';
var pixelPath = 'https://sgtm.simoahava.com/4dchk';
// Prevent the script from running outside the home page
if (document.location.pathname !== '/') return;
// Inject the bait file
var el = document.createElement('script');
el.src = baitPath;
document.body.appendChild(el);
var gaBlocked = false;
// Run the detections at page load to avoid race conditions
window.addEventListener('load', function() {
// Send a HEAD request for the Universal Analytics library to see if it's blocked
fetch('https://www.google-analytics.com/analytics.js', {method: 'HEAD', mode: 'no-cors'})
.catch(function() {
// If the load failed, assume GA was blocked
gaBlocked = true;
})
.finally(function() {
// Build the GA4 parameters, add additional parameters at your leisure
var params = {
ads_blocked: !document.querySelector('#GxsCRdhiJi'), // Detect if the bait file was blocked
gtm_blocked: !(window.google_tag_manager && window.google_tag_manager.dataLayer), // Detect if gtm.js was blocked
ga_blocked: gaBlocked // Detect if analytics.js was blocked
};
// Build the pixel request with a unique, random Client ID
var cid = Math.floor((Math.random() * 1000000) + 1) + '_' + new Date().getTime();
var img = document.createElement('img');
img.style = 'width: 1; height: 1; display: none;';
img.src = pixelPath + '?client_id=' + cid + '&' + Object.keys(params).reduce(function(acc, cur) { return acc.concat(cur + '=' + params[cur]);}, []).join('&');
document.body.appendChild(img);
});
});
})();
for baitPath
When pixelPath
で、クライアント テンプレートに追加した対応する設定を構成します。 Default values are: /ads-min.js
decoy file path, and /4dchk
for pixel paths.
Ad blocker measurement
To measure the impact of ad blocker
A browser sends a request to the server container. pick it up. Requests should be for files most commonly blocked by ad blockers, such as: ads-min.js.
...
var baitPath = 'https://sgtm.simoahava.com/ads-min.js';
var el = document.createElement('script');
el.src = baitPath;
document.body.appendChild(el);
...
The purpose of this file is to identify specific IDs (GxsCRdhiJi
if you are using the default template). If the element doesn’t exist when you query it, it means the download failed for some reason, one of which could be an ad blocker.
warning: ダウンロードに失敗した理由は不明です。 An ad blocker could be the cause, but it could also be a network error or something else.したがって、この点に関しては常に不確実性があります。
Also note the filter list that looks like this: Disconnect.me
Measurement of GA blockers
We use a very simple method to measure if Google Analytics is blocked.i run fetch()
Call the Universal Analytics JavaScript library. If that request fails, we determine that GA is blocked.
Requests are sent with the HEAD method so as not to consume browser resources. no-cors
Mode to avoid CORS issues.
The request looks like this:
...
fetch('https://www.google-analytics.com/analytics.js', {method: 'HEAD', mode: 'no-cors'})
.catch(() => {
// GA is blocked
});
...
warning: Again, I’m not sure if it’s a blocker that prevents GA from loading.Also, in Firefox for example, you can load Google Analytics in a private window, but the main method is Sim prevent it from working. This particular approach cannot detect that type of blocking.
Measurement of GTM blockers
For GTM, flat A simpler approach. when the window loads window.google_tag_manager
An interface is created and there is also a nested object window.google_tag_manager.dataLayer
.
...
gtm_blocked: !(window.google_tag_manager && window.google_tag_manager.dataLayer)
...
warning: 前述のすべての警告が再び適用されます。For example in Firefox the global
window.google_tag_manager
interface teeth was created, but sincedataLayer.push
GTM itself will not work if it is shimmed.
Send pixel requests to the server container
Once we have the boolean value of whether these three vectors are blocked, we put them all together.
window.addEventListener('load', function() {
fetch('https://www.google-analytics.com/analytics.js', {method: 'HEAD', mode: 'no-cors'})
.catch(function() {
gaBlocked = true;
})
.finally(function() {
var params = {
ads_blocked: !document.querySelector('#GxsCRdhiJi'),
gtm_blocked: !(window.google_tag_manager && window.google_tag_manager.dataLayer),
ga_blocked: gaBlocked
};
var cid = Math.floor((Math.random() * 1000000) + 1) + '_' + new Date().getTime();
var img = document.createElement('img');
img.style = 'width: 1; height: 1; display: none;';
img.src = pixelPath + '?client_id=' + cid + '&' + Object.keys(params).reduce(function(acc, cur) { return acc.concat(cur + '=' + params[cur]);}, []).join('&');
document.body.appendChild(img);
});
});
Pixel requests wait until the window is fully loaded. When of Google Analytics fetch()
Request to complete.このようにして、非同期競合状態が発生しても測定が損なわれることはありません。
in the params
You can add any parameter that ends with the event data object.if you please do not offer page_location
It is necessary to add parameters to the tag (see below).カスタムを提供することもできます event_name
parameter and the client template defaults to page_view
If I do not.
of client_id
It is automatically generated as a unique random value for each request.
warning: This means you are not measuring user instead of using blockers personal hit blocked or not.wanted to ignore user There’s a simple reason I don’t want to start setting cookies and fingerprints just for this exercise.
Set GA4 tags
In the server container, you can set the GA4 tag to fire when this particular event data object is generated. For this purpose, We recommend creating a new data stream specifically for this data
As you can see, we edit the visitor’s IP address (I think it is an essential setting in All Ga4 measurement).
Don’t forget to add the measurement ID of your data stream to the tag. You don’t need to add custom parameters from your pixel request. It is automatically sent to GA4 just by being present in the event data object.
Finally the trigger looks like this:
Test your setup
request is displayed. /ads-min.js
followed immediately by the next request /4dchk
pixel.
In Google Analytics 4, you should be able to see the events in real-time reports.
Note that all other factors in GA4 are roughly flat. It doesn’t measure user activity and engagement correctly because it doesn’t use the recommended SDKs. But we don’t mind that. We only care about events.
Then you can use them to compile to the report you want expedition Google Analytics 4 or google big query If you configured export for this data stream.
Don’t forget to test with different blockers too.たとえば、Brave ブラウザーでホームページを読み込むと、ブラウザーのネットワーク リクエストは次のようになります。
As you can see, all three parameters have values. true
indicating that everything is blocked in Brave.
However, in Firefox Private Windows:
nothing is blocked!
well i am using ads-min.js
As a decoy file and as a filter list used by Firefox (Disconnect.me) matches the tracking domain itself, not the file name. GA and GTM are technically different, I was blockedtheir main methods are Simwhich means it won’t work in Firefox.
Shimming
Overview
You may have noticed a number of caveats in the article.This is to detect ad and content blockers is difficult.
detection The way, not the blocker measurement their impact.
This is another great use case for server containers.
Using this method, you can selectively block the server tag from firing if the user is using an ad blocker.もちろん、これは、ユーザーがブロッカーを使用して単純にブロックするユース ケースには役に立ちません。 Any Prevents unrelated scripts from launching in your browser. It’s up to you how much you respect the user’s wishes.
In case you’re interested, in my testing I found the following:
- ~7% where the page load occurred Google Tag Manager blocked.
- ~10% where the page load occurred google analytics blocked.
- ~18% where the page load occurred ads-min.js So by proxy, advertisement blocked.
If you have any questions about this setting, or any comments about ad/content blocking in general, let us know in the comments.