Wednesday, November 22, 2023
HomeWeb AnalysisHow to check if content is blocked?

How to check if content is blocked?

iOS9 has been released, and the ad blocking (content blocking) function has become a hot topic in some areas. I also downloaded a content blocking app and what is being blocked? what is not blocked? etc. was tested.

It was as expected that ads were blocked because it was the main purpose of the app, but it also blocked access analysis tools such as Google Analytics and tag management tools such as Google Tag Manager. has caused ripples even among web marketers who have nothing to do with advertising.

In this article, I would like to think about how to check what percentage of users visiting my site have been content blocked.

How do content blocks work?

First, I’d check Apple’s developer documentation. The official documentation is

iOS Developer Library – Content Blocking Safari Extensions

is provided in the form of Although the document is in English, it seems that content blocking is achieved by specifying the following JavaScript for the Safari extension.

        "action": {
            "type": "block"
        "trigger": {
            "url-filter": ""
        "action": {
            "selector": "a[href^=\"\"]",
            "type": "css-display-none"
        "trigger": {
            "url-filter": ".*"

The first example seems to block resource loading based on the URL. Also, in the second example, it seems that the CSS style is set to display: none based on the CSS selector to prevent screen display.

Originally, I think one of the purposes of content blocking is to reduce the amount of data to be read, so I think that many of them block reading based on URLs. On top of that, it seems that the second form of frame hiding is also used in order to hide the ad display frames that have not been loaded.

Since the URL to be blocked is specified as url-filter, for Google Analytics and Google Tag Manager, if you download the respective library JavaScript on your own server and load it from there, the blocked URL It seems that the block can be avoided by reading the resource from a URL that is not listed in the URL.

How to check if you are blocked

As mentioned above, if the content is blocked, the JavaScript library of Google Analytics and Google Tag Manager cannot be loaded, so to check whether Google Tag Manager or Google Analytics is blocked, use It seems that it can be checked by whether or not the JavaScript function defined in exists. In Qiita and some articles, there are articles that judge by the class name on the DOM. Actually, there are two types of content blocking methods, URL-based and CSS selector-based, so I think it is possible to judge by the class name on the DOM, but the target to check the block is Google Tag Manager and Google If you’re just focusing on analytics, I think this is the simplest way to go.

In particular,

;(function (window) {
  var ContentsBlockChecker = function () {};
  ContentsBlockChecker.prototype.isBlockGoogleTagManager = function () {
    return typeof(window.google_tag_manager) === 'undefined';
  ContentsBlockChecker.prototype.isBlockUniversalAnalytics = function () {
    return typeof(window[window['GoogleAnalyticsObject']].getByName) === 'undefined';
  ContentsBlockChecker.prototype.isBlockGoogleAnalyticsAsync = function () {
    return == "[object Array]";
  ContentsBlockChecker.prototype.isBlockGoogleAnalyticsSync = function () {
    return == '[object Undefined]';

  ContentsBlockChecker.prototype.isBlock = function () {
    return {
      'GoogleTagManager': this.isBlockGoogleTagManager(),
      'UniversalAnalytics': this.isBlockUniversalAnalytics(),
      'GoogleAnalyticsAsync': this.isBlockGoogleAnalyticsAsync(),
      'GoogleAnalyticsSync': this.isBlockGoogleAnalyticsSync()
  window.ContentsBlockChecker = ContentsBlockChecker;

load JavaScript like

var checker = new ContentsBlockChecker();
if (checker.isBlockUniversalAnalytics()) {
  // ユニバーサルアナリティクスがブロックされています
} else {
  // ユニバーサルアナリティクスはブロックされていません

can be determined in such a way.

In the above, a check function is also created for the old Google Analytics (synchronous version, asynchronous version), but this operation test is insufficient, so please be careful when using it.

Test your content block usage now

So, in this blog, I have implemented the above JavaScript code. Once I have a certain amount of access, I hope to be able to publish how many users are using content blocks based on the data on this blog. But).

If you have a site with a lot of access (especially if you have a lot of access from mobile phones, it is easy to refer to), and if you would like to cooperate with a survey similar to this site, please contact us from the inquiry form . I’m happy to hear that.


Leave a reply

Please enter your comment!
Please enter your name here

Recent Posts

Popular Posts

Most Popular

Recent Comments