निजता और मैसेज सेवा JavaScript एपीआई के नमूने

अपने ट्रैफ़िक के रैंडम सैंपल के लिए मैसेज दिखाएं

<script>
  // Make sure that the googlefc property exists on the window.
  window.googlefc = window.googlefc || {};
  // To guarantee functionality, this must go before the tag on the page.
  googlefc.controlledMessagingFunction = (message) => {
    // Show the message to 10% of traffic.
    var percentageToShowTo = 10;

    // Pick a random number between 0 and 100.
    var rand = Math.random() * 100;

    if (rand <= percentageToShowTo) {
      message.proceed(true);
    } else {
      message.proceed(false);
    }
  };
</script>

सदस्यों को यह मैसेज न दिखाएं

(यह मानकर चलता है कि आपके पास यह जानकारी देने वाला फ़ंक्शन है कि उपयोगकर्ता सदस्य है या नहीं)

<script>
  // Make sure that the googlefc property exists on the window.
  window.googlefc = window.googlefc || {};
  // To guarantee functionality, this must go before the tag on the page.
  googlefc.controlledMessagingFunction = (message) => {
    // checkSubscriptionStatus() is an example of a function that may exist
    // in your codebase that resolves a promise with true or false depending on
    // whether the user on the page is a subscriber.
    checkSubscriptionStatus().then(
      function (isSubscriber) {
        // Do not show the message if a user is a subscriber.
        if (isSubscriber) {
          message.proceed(false);
        } else {
          message.proceed(true);
        }
      }
    );
  }
</script>

अपने होम पेज के अलावा, मैसेज को हर जगह दिखाएं

<script>
  // Make sure that the googlefc property exists on the window.
  window.googlefc = window.googlefc || {};
  // To guarantee functionality, this must go before the tag on the page.
  googlefc.controlledMessagingFunction = (message) => {
    var pathname = location.pathname;

    // This assumes other pages on your site are differentiated with a different
    // path. `location.href` can also be used if more information is needed to
    // differentiate between the home page and other pages on the site.
    if (pathname.length > 1) {
      message.proceed(true);
    } else {
      message.proceed(false);
    }
  };
</script>

किसी खास पेज व्यू के बाद ही मैसेज दिखाएं

(यह मानते हुए कि पेज व्यू की संख्या ट्रैक करने के लिए आपके पास कुकी या कोई दूसरा तरीका है)

<script>
  // Make sure that the googlefc property exists on the window.
  window.googlefc = window.googlefc || {};
  // To guarantee functionality, this must go before the tag on the page.
  googlefc.controlledMessagingFunction = (message) => {
    // How many pageviews before the message is shown.
    var freePageviewsLimit = 3;

    // Check how many pages the user has seen.
    var pagesViewed = getPagesViewed();

    // Show the message if the user has seen more pages than the free limit.
    if (pagesViewed >= freePageviewsLimit) {
      message.proceed(true);
    } else {
      message.proceed(false);
    }
  };
</script>

न्यूज़ टैगिंग गाइड (NTG) की मदद से, Google Analytics में अनुमति वाले विज्ञापनों और विज्ञापन रोकने वाले उपयोगकर्ताओं से जुड़े इवेंट ट्रैक करें

UA-xxxxxxxxx-x को खाते के सही ट्रैकिंग आईडी से बदलें.

न्यूज़ टैगिंग गाइड के बारे में ज़्यादा जानकारी के लिए, यहां जाएं.

<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-xxxxxxxxx-x', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->

<script>
  // Make sure that the googlefc property exists on the window.
  window.googlefc = window.googlefc || {};
  googlefc.callbackQueue = googlefc.callbackQueue || [];
  googlefc.callbackQueue.push({
    'AD_BLOCK_DATA_READY': function() {
      switch (googlefc.getAdBlockerStatus()) {
        case googlefc.AdBlockerStatusEnum.EXTENSION_LEVEL_AD_BLOCKER:
        case googlefc.AdBlockerStatusEnum.NETWORK_LEVEL_AD_BLOCKER:
          ga('send', 'event', {
            eventCategory: 'NTG adblock',
            eventAction: 'detected',
            eventLabel: '<page url>',
            nonInteraction: true
          });
          break;
      }
      switch (googlefc.getAllowAdsStatus()) {
        case googlefc.AllowAdsStatusEnum.ADS_ALLOWED:
          ga('send', 'event', {
            eventCategory: 'NTG adblock',
            eventAction: 'allow-ads',
            eventLabel: '<page url>',
            nonInteraction: true
          });
          break;
      }
   }});
</script>

उपयोगकर्ताओं के विज्ञापन रोकने वाले इस्तेमाल का पता लगाने के लिए Google Analytics में इवेंट ट्रैक करें

इसका इस्तेमाल यह तय करने के लिए किया जा सकता है कि कितने प्रतिशत उपयोगकर्ता, नेटवर्क-लेवल पर विज्ञापन रोकने वाले एक्सटेंशन, एक्सटेंशन-लेवल वाले विज्ञापन रोकने वाले या कोई भी विज्ञापन रोकने वाले का इस्तेमाल नहीं कर रहे हैं.

UA-xxxxxxxxx-x को खाते के सही ट्रैकिंग आईडी से बदलें.

Analytics के बारे में ज़्यादा जानकारी के लिए, Google Analytics Docs देखें.

<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-xxxxxxxxx-x', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->

<script>
  // Make sure that the googlefc property exists on the window.
  window.googlefc = window.googlefc || {};
  googlefc.callbackQueue = googlefc.callbackQueue || [];
  googlefc.callbackQueue.push({
    'AD_BLOCK_DATA_READY': function() {
      var analyticsData = {
          hitType: 'event',
          eventCategory: 'Funding Choices',
          eventAction: 'Ad Blocking Type'
        };
      switch (googlefc.getAdBlockerStatus()) {
        case googlefc.AdBlockerStatusEnum.EXTENSION_LEVEL_AD_BLOCKER:
          analyticsData.eventLabel = 'EXTENSION_LEVEL_AD_BLOCKER';
          ga('send', analyticsData);
          break;
        case googlefc.AdBlockerStatusEnum.NETWORK_LEVEL_AD_BLOCKER:
          analyticsData.eventLabel = 'NETWORK_LEVEL_AD_BLOCKER';
          ga('send', analyticsData);
          break;
        case googlefc.AdBlockerStatusEnum.NO_AD_BLOCKER:
          analyticsData.eventLabel = 'NO_AD_BLOCKER';
          ga('send', analyticsData);
          break;
      }
   }});
</script>