Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Scroll Depth Release: make pageleave script the new default (#5105)
RobertJoonas079b40068c17
diff --git a/test/plausible_web/plugs/tracker_test.exs b/test/plausible_web/plugs/tracker_test.exsindex c99de70da8..bf1d59f4ad 100644--- a/test/plausible_web/plugs/tracker_test.exs+++ b/test/plausible_web/plugs/tracker_test.exs@@ -42,6 +42,17 @@ defmodule PlausibleWeb.TrackerTest doassert response == get_script("plausible.outbound-links.file-downloads.compat.hash.js")end+ test "pageleave extension" do+ # Some customers who have participated in the private preview of the+ # scroll depth feature, have updated their tracking scripts to+ # `script.pageleave.js` per our request. With the public release of+ # scroll depth, this functionality is included in the default script,+ # but we must continue to serve `script.pageleave.js` for as long as+ # those customers are still using it.+ assert get_script("script.pageleave.js") == get_script("script.js")+ assert get_script("script.manual.pageleave.js") == get_script("script.manual.js")+ end+def get_script(filename) doopts = PlausibleWeb.Tracker.init([])diff --git a/tracker/report-sizes.js b/tracker/report-sizes.jsindex 01f63ab434..04dbe15de5 100644--- a/tracker/report-sizes.js+++ b/tracker/report-sizes.js@@ -6,9 +6,9 @@ const PrivTrackerDir = '../priv/tracker/js/';const toReport = ['plausible.js',- 'plausible.pageleave.js',- 'plausible.manual.pageleave.js',- 'plausible.hash.pageleave.js'+ 'plausible.compat.js',+ 'plausible.manual.js',+ 'plausible.hash.js'];const results = [];diff --git a/tracker/src/plausible.js b/tracker/src/plausible.jsindex 45b1d2780e..b6a87f1304 100644--- a/tracker/src/plausible.js+++ b/tracker/src/plausible.js@@ -16,11 +16,9 @@if (reason) console.warn('Ignoring Event: ' + reason);options && options.callback && options.callback()- {{#if pageleave}}if (eventName === 'pageview') {currentEngagementIgnored = true}- {{/if}}}function defaultEndpoint(el) {@@ -34,9 +32,6 @@{{/if}}}- {{#if pageleave}}- // :NOTE: Tracking engagement events is currently experimental.-var currentEngagementIgnoredvar currentEngagementURL = location.hrefvar currentEngagementProps = {}@@ -47,7 +42,7 @@// prevents registering multiple listeners in those cases.var listeningOnEngagement = false- // In SPA-s, multiple listeners that trigger the pageleave event+ // In SPA-s, multiple listeners that trigger the engagement event// might fire nearly at the same time. E.g. when navigating back// in browser history while using hash-based routing - a popstate// and hashchange will be fired in a very quick succession. This@@ -170,7 +165,6 @@listeningOnEngagement = true}}- {{/if}}function trigger(eventName, options) {var isPageview = eventName === 'pageview'@@ -257,7 +251,6 @@payload.h = 1{{/if}}- {{#if pageleave}}if (isPageview) {currentEngagementIgnored = falsecurrentEngagementURL = payload.u@@ -267,7 +260,6 @@runningEnagementStart = Date.now()registerEngagementListener()}- {{/if}}sendRequest(endpoint, payload, options)}@@ -315,13 +307,11 @@if (isSPANavigation && lastPage === location.pathname) return;{{/unless}}- {{#if pageleave}}if (isSPANavigation && listeningOnEngagement) {triggerEngagement()currentDocumentHeight = getDocumentHeight()maxScrollDepthPx = getCurrentScrollDepthPx()}- {{/if}}lastPage = location.pathnametrigger('pageview')@@ -355,14 +345,12 @@page()}- {{#if pageleave}}window.addEventListener('pageshow', function(event) {if (event.persisted) {// Page was restored from bfcache - trigger a pageviewpage();}})- {{/if}}{{/unless}}{{#if (any outbound_links file_downloads tagged_events)}}diff --git a/tracker/test/fixtures/engagement-hash-exclusions.html b/tracker/test/fixtures/engagement-hash-exclusions.htmlindex aecca154e9..cc5a5502cb 100644--- a/tracker/test/fixtures/engagement-hash-exclusions.html+++ b/tracker/test/fixtures/engagement-hash-exclusions.html@@ -6,7 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Plausible Playwright tests</title>- <script defer data-exclude='/*#*/hash/**/ignored' src="/tracker/js/plausible.exclusions.hash.local.pageleave.js"></script>+ <script defer data-exclude='/*#*/hash/**/ignored' src="/tracker/js/plausible.exclusions.hash.local.js"></script></head><body>diff --git a/tracker/test/fixtures/engagement-hash-pageview-props.html b/tracker/test/fixtures/engagement-hash-pageview-props.htmlindex 651acdb034..a4fa6ef780 100644--- a/tracker/test/fixtures/engagement-hash-pageview-props.html+++ b/tracker/test/fixtures/engagement-hash-pageview-props.html@@ -6,7 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Plausible Playwright tests</title>- <script id="plausible-script" defer src="/tracker/js/plausible.hash.local.pageleave.pageview-props.js"></script>+ <script id="plausible-script" defer src="/tracker/js/plausible.hash.local.pageview-props.js"></script></head><body>diff --git a/tracker/test/fixtures/engagement-hash.html b/tracker/test/fixtures/engagement-hash.htmlindex b6caf9b9a3..56adccdaa7 100644--- a/tracker/test/fixtures/engagement-hash.html+++ b/tracker/test/fixtures/engagement-hash.html@@ -6,7 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Plausible Playwright tests</title>- <script defer src="/tracker/js/plausible.hash.local.pageleave.js"></script>+ <script defer src="/tracker/js/plausible.hash.local.js"></script><script></script>diff --git a/tracker/test/fixtures/engagement-manual.html b/tracker/test/fixtures/engagement-manual.htmlindex f87f00b322..c5e560a4a6 100644--- a/tracker/test/fixtures/engagement-manual.html+++ b/tracker/test/fixtures/engagement-manual.html@@ -6,7 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Plausible Playwright tests</title>- <script defer src="/tracker/js/plausible.local.manual.pageleave.js"></script>+ <script defer src="/tracker/js/plausible.local.manual.js"></script><script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script></head>diff --git a/tracker/test/fixtures/engagement-pageview-props.html b/tracker/test/fixtures/engagement-pageview-props.htmlindex c2c9cd11e3..866425bc86 100644--- a/tracker/test/fixtures/engagement-pageview-props.html+++ b/tracker/test/fixtures/engagement-pageview-props.html@@ -6,7 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Plausible Playwright tests</title>- <script defer event-author="John" src="/tracker/js/plausible.local.pageleave.pageview-props.js"></script>+ <script defer event-author="John" src="/tracker/js/plausible.local.pageview-props.js"></script></head><body>diff --git a/tracker/test/fixtures/engagement.html b/tracker/test/fixtures/engagement.htmlindex 3b238f95d2..040dde8391 100644--- a/tracker/test/fixtures/engagement.html+++ b/tracker/test/fixtures/engagement.html@@ -6,7 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Plausible Playwright tests</title>- <script defer src="/tracker/js/plausible.local.pageleave.js"></script>+ <script defer src="/tracker/js/plausible.local.js"></script></head><body>diff --git a/tracker/test/fixtures/scroll-depth-content-onscroll.html b/tracker/test/fixtures/scroll-depth-content-onscroll.htmlindex 588776c2cf..231a238121 100644--- a/tracker/test/fixtures/scroll-depth-content-onscroll.html+++ b/tracker/test/fixtures/scroll-depth-content-onscroll.html@@ -6,7 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Plausible Playwright tests</title>- <script defer src="/tracker/js/plausible.local.pageleave.js"></script>+ <script defer src="/tracker/js/plausible.local.js"></script></head><body>diff --git a/tracker/test/fixtures/scroll-depth-dynamic-content-load.html b/tracker/test/fixtures/scroll-depth-dynamic-content-load.htmlindex 6cd3a77185..bd1e18357d 100644--- a/tracker/test/fixtures/scroll-depth-dynamic-content-load.html+++ b/tracker/test/fixtures/scroll-depth-dynamic-content-load.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>- <script defer src="/tracker/js/plausible.local.pageleave.js"></script>+ <script defer src="/tracker/js/plausible.local.js"></script></head><body><br>diff --git a/tracker/test/fixtures/scroll-depth-hash.html b/tracker/test/fixtures/scroll-depth-hash.htmlindex 359ba5548c..efeafb44d7 100644--- a/tracker/test/fixtures/scroll-depth-hash.html+++ b/tracker/test/fixtures/scroll-depth-hash.html@@ -6,7 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Plausible Playwright tests</title>- <script defer src="/tracker/js/plausible.hash.local.pageleave.js"></script>+ <script defer src="/tracker/js/plausible.hash.local.js"></script></head><body>diff --git a/tracker/test/fixtures/scroll-depth-slow-window-load.html b/tracker/test/fixtures/scroll-depth-slow-window-load.htmlindex eea2a5fa29..ace9d5bc07 100644--- a/tracker/test/fixtures/scroll-depth-slow-window-load.html+++ b/tracker/test/fixtures/scroll-depth-slow-window-load.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>- <script defer src="/tracker/js/plausible.local.pageleave.js"></script>+ <script defer src="/tracker/js/plausible.local.js"></script></head><body><a id="navigate-away" href="/manual.html">diff --git a/tracker/test/fixtures/scroll-depth.html b/tracker/test/fixtures/scroll-depth.htmlindex 23aad7c4aa..0c421defa4 100644--- a/tracker/test/fixtures/scroll-depth.html+++ b/tracker/test/fixtures/scroll-depth.html@@ -3,7 +3,7 @@<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">- <script defer src="/tracker/js/plausible.local.pageleave.js"></script>+ <script defer src="/tracker/js/plausible.local.js"></script><title>Document</title></head><body>