From a378935aacdd7c57105c3d9b9178347bc6704ee2 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 17 Jun 2021 10:55:45 +0300 Subject: [PATCH] Add IE11 compatibility mode --- lib/plausible_web/plugs/tracker.ex | 2 +- priv/tracker/js/plausible.compat.exclusions.hash.js | 1 + .../js/plausible.compat.exclusions.hash.outbound-links.js | 1 + priv/tracker/js/plausible.compat.exclusions.js | 1 + priv/tracker/js/plausible.compat.exclusions.outbound-links.js | 1 + priv/tracker/js/plausible.compat.hash.js | 1 + priv/tracker/js/plausible.compat.hash.outbound-links.js | 1 + priv/tracker/js/plausible.compat.js | 1 + priv/tracker/js/plausible.compat.outbound-links.js | 1 + tracker/compile.js | 2 +- tracker/src/plausible.js | 4 ++++ 11 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 priv/tracker/js/plausible.compat.exclusions.hash.js create mode 100644 priv/tracker/js/plausible.compat.exclusions.hash.outbound-links.js create mode 100644 priv/tracker/js/plausible.compat.exclusions.js create mode 100644 priv/tracker/js/plausible.compat.exclusions.outbound-links.js create mode 100644 priv/tracker/js/plausible.compat.hash.js create mode 100644 priv/tracker/js/plausible.compat.hash.outbound-links.js create mode 100644 priv/tracker/js/plausible.compat.js create mode 100644 priv/tracker/js/plausible.compat.outbound-links.js diff --git a/lib/plausible_web/plugs/tracker.ex b/lib/plausible_web/plugs/tracker.ex index ee399fa017..61a808e204 100644 --- a/lib/plausible_web/plugs/tracker.ex +++ b/lib/plausible_web/plugs/tracker.ex @@ -2,7 +2,7 @@ defmodule PlausibleWeb.Tracker do import Plug.Conn use Agent - base_variants = ["hash", "outbound-links", "exclusions"] + base_variants = ["hash", "outbound-links", "exclusions", "compat"] # Generates Power Set of all variants variants = diff --git a/priv/tracker/js/plausible.compat.exclusions.hash.js b/priv/tracker/js/plausible.compat.exclusions.hash.js new file mode 100644 index 0000000000..d685b93eed --- /dev/null +++ b/priv/tracker/js/plausible.compat.exclusions.hash.js @@ -0,0 +1 @@ +!function(){"use strict";var e,r=window.location,o=window.document,l=o.getElementById("plausible"),s=l.getAttribute("data-api")||new URL(l.src).origin+"/api/event",w=window.localStorage.plausible_ignore,d=l&&l.getAttribute("data-exclude").split(",");function p(e){console.warn("Ignoring Event: "+e)}function t(e,t){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(r.hostname)||"file:"===r.protocol)return p("localhost");if(!(window.phantom||window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){if("true"==w)return p("localStorage flag");if(d)for(var i=0;i a.length > 0).map(a => a.sort()); compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/plausible.js')) diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js index 2209c6b8b3..6511f57506 100644 --- a/tracker/src/plausible.js +++ b/tracker/src/plausible.js @@ -4,7 +4,11 @@ var location = window.location var document = window.document + {{#if compat}} + var scriptEl = document.getElementById('plausible'); + {{else}} var scriptEl = document.currentScript; + {{/if}} var endpoint = scriptEl.getAttribute('data-api') || new URL(scriptEl.src).origin + '/api/event' var plausible_ignore = window.localStorage.plausible_ignore; {{#if exclusions}}