← back to CelebritySignatures

apps/mobile/ui/no-track.ts

51 lines

// Injected into every in-app WebView BEFORE page content loads, so the App
// Store binary performs NO ad/analytics tracking (App Privacy = "not used to
// track you", so no ATT prompt is required). The public website keeps its
// AdSense/analytics; only the native app is clean. (Reused verbatim from the
// Charge & Explore app — same Google ad/analytics script set to block.)
export const NO_TRACK = `
(function () {
  try {
    window.__IN_APP_NO_ADS__ = true;
    window.adsbygoogle = { loaded: true, push: function () {} };
    window.gtag = function () {};
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push = function () {};
    var BLOCK = /googlesyndication|pagead2|adsbygoogle|doubleclick|google-analytics|googletagmanager|gtag\\/js|connect\\.facebook|fbevents|fbq|mixpanel|segment\\.(io|com)|amplitude|hotjar|matomo/i;
    var origCreate = document.createElement.bind(document);
    document.createElement = function (tag) {
      var el = origCreate(tag);
      if (String(tag).toLowerCase() === 'script') {
        try {
          var d = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');
          Object.defineProperty(el, 'src', {
            configurable: true,
            get: function () { return d.get.call(this); },
            set: function (v) { if (BLOCK.test(String(v))) return; d.set.call(this, v); },
          });
          var setAttr = el.setAttribute.bind(el);
          el.setAttribute = function (name, value) {
            if (String(name).toLowerCase() === 'src' && BLOCK.test(String(value))) return;
            return setAttr(name, value);
          };
        } catch (e) {}
      }
      return el;
    };
    var kill = function (n) {
      if (n && n.tagName === 'SCRIPT') {
        var src = n.src || (n.getAttribute && n.getAttribute('src')) || '';
        if (BLOCK.test(String(src))) { try { n.type = 'javascript/blocked'; } catch (e) {} try { n.remove(); } catch (e) {} }
      }
    };
    new MutationObserver(function (muts) {
      for (var i = 0; i < muts.length; i++) {
        var an = muts[i].addedNodes || [];
        for (var j = 0; j < an.length; j++) kill(an[j]);
      }
    }).observe(document.documentElement || document, { childList: true, subtree: true });
  } catch (e) {}
})();
true;
`;