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
Revert "Scroll Depth Release: make pageleave script the new default (#5105)" (#5112)
RobertJoonas7dd566499226
diff --git a/test/plausible_web/plugs/tracker_test.exs b/test/plausible_web/plugs/tracker_test.exsindex bf1d59f4ad..c99de70da8 100644--- a/test/plausible_web/plugs/tracker_test.exs+++ b/test/plausible_web/plugs/tracker_test.exs@@ -42,17 +42,6 @@ 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 04dbe15de5..01f63ab434 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.compat.js',- 'plausible.manual.js',- 'plausible.hash.js'+ 'plausible.pageleave.js',+ 'plausible.manual.pageleave.js',+ 'plausible.hash.pageleave.js'];const results = [];diff --git a/tracker/src/plausible.js b/tracker/src/plausible.jsindex b6a87f1304..45b1d2780e 100644--- a/tracker/src/plausible.js+++ b/tracker/src/plausible.js@@ -16,9 +16,11 @@if (reason) console.warn('Ignoring Event: ' + reason);options && options.callback && options.callback()+ {{#if pageleave}}if (eventName === 'pageview') {currentEngagementIgnored = true}+ {{/if}}}function defaultEndpoint(el) {@@ -32,6 +34,9 @@{{/if}}}+ {{#if pageleave}}+ // :NOTE: Tracking engagement events is currently experimental.+var currentEngagementIgnoredvar currentEngagementURL = location.hrefvar currentEngagementProps = {}@@ -42,7 +47,7 @@// prevents registering multiple listeners in those cases.var listeningOnEngagement = false- // In SPA-s, multiple listeners that trigger the engagement event+ // In SPA-s, multiple listeners that trigger the pageleave 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@@ -165,6 +170,7 @@listeningOnEngagement = true}}+ {{/if}}function trigger(eventName, options) {var isPageview = eventName === 'pageview'@@ -251,6 +257,7 @@payload.h = 1{{/if}}+ {{#if pageleave}}if (isPageview) {currentEngagementIgnored = falsecurrentEngagementURL = payload.u@@ -260,6 +267,7 @@runningEnagementStart = Date.now()registerEngagementListener()}+ {{/if}}sendRequest(endpoint, payload, options)}@@ -307,11 +315,13 @@if (isSPANavigation && lastPage === location.pathname) return;{{/unless}}+ {{#if pageleave}}if (isSPANavigation && listeningOnEngagement) {triggerEngagement()currentDocumentHeight = getDocumentHeight()maxScrollDepthPx = getCurrentScrollDepthPx()}+ {{/if}}lastPage = location.pathnametrigger('pageview')@@ -345,12 +355,14 @@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 cc5a5502cb..aecca154e9 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.js"></script>+ <script defer data-exclude='/*#*/hash/**/ignored' src="/tracker/js/plausible.exclusions.hash.local.pageleave.js"></script></head><body>diff --git a/tracker/test/fixtures/engagement-hash-pageview-props.html b/tracker/test/fixtures/engagement-hash-pageview-props.htmlindex a4fa6ef780..651acdb034 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.pageview-props.js"></script>+ <script id="plausible-script" defer src="/tracker/js/plausible.hash.local.pageleave.pageview-props.js"></script></head><body>diff --git a/tracker/test/fixtures/engagement-hash.html b/tracker/test/fixtures/engagement-hash.htmlindex 56adccdaa7..b6caf9b9a3 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.js"></script>+ <script defer src="/tracker/js/plausible.hash.local.pageleave.js"></script><script></script>diff --git a/tracker/test/fixtures/engagement-manual.html b/tracker/test/fixtures/engagement-manual.htmlindex c5e560a4a6..f87f00b322 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.js"></script>+ <script defer src="/tracker/js/plausible.local.manual.pageleave.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 866425bc86..c2c9cd11e3 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.pageview-props.js"></script>+ <script defer event-author="John" src="/tracker/js/plausible.local.pageleave.pageview-props.js"></script></head><body>diff --git a/tracker/test/fixtures/engagement.html b/tracker/test/fixtures/engagement.htmlindex 040dde8391..3b238f95d2 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.js"></script>+ <script defer src="/tracker/js/plausible.local.pageleave.js"></script></head><body>diff --git a/tracker/test/fixtures/scroll-depth-content-onscroll.html b/tracker/test/fixtures/scroll-depth-content-onscroll.htmlindex 231a238121..588776c2cf 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.js"></script>+ <script defer src="/tracker/js/plausible.local.pageleave.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 bd1e18357d..6cd3a77185 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.js"></script>+ <script defer src="/tracker/js/plausible.local.pageleave.js"></script></head><body><br>diff --git a/tracker/test/fixtures/scroll-depth-hash.html b/tracker/test/fixtures/scroll-depth-hash.htmlindex efeafb44d7..359ba5548c 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.js"></script>+ <script defer src="/tracker/js/plausible.hash.local.pageleave.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 ace9d5bc07..eea2a5fa29 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.js"></script>+ <script defer src="/tracker/js/plausible.local.pageleave.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 0c421defa4..23aad7c4aa 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.js"></script>+ <script defer src="/tracker/js/plausible.local.pageleave.js"></script><title>Document</title></head><body>