Skip to content

Commit

Permalink
Revert "Scroll Depth Release: make pageleave script the new default (#…
Browse files Browse the repository at this point in the history
…5105)" (#5112)

This reverts commit 079b400.
  • Loading branch information
RobertJoonas authored Feb 25, 2025
1 parent 079b400 commit 7dd5664
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 26 deletions.
11 changes: 0 additions & 11 deletions test/plausible_web/plugs/tracker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ defmodule PlausibleWeb.TrackerTest do
assert 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) do
opts = PlausibleWeb.Tracker.init([])

Expand Down
6 changes: 3 additions & 3 deletions tracker/report-sizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
14 changes: 13 additions & 1 deletion tracker/src/plausible.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -32,6 +34,9 @@
{{/if}}
}

{{#if pageleave}}
// :NOTE: Tracking engagement events is currently experimental.

var currentEngagementIgnored
var currentEngagementURL = location.href
var currentEngagementProps = {}
Expand All @@ -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
Expand Down Expand Up @@ -165,6 +170,7 @@
listeningOnEngagement = true
}
}
{{/if}}

function trigger(eventName, options) {
var isPageview = eventName === 'pageview'
Expand Down Expand Up @@ -251,6 +257,7 @@
payload.h = 1
{{/if}}

{{#if pageleave}}
if (isPageview) {
currentEngagementIgnored = false
currentEngagementURL = payload.u
Expand All @@ -260,6 +267,7 @@
runningEnagementStart = Date.now()
registerEngagementListener()
}
{{/if}}

sendRequest(endpoint, payload, options)
}
Expand Down Expand Up @@ -307,11 +315,13 @@
if (isSPANavigation && lastPage === location.pathname) return;
{{/unless}}

{{#if pageleave}}
if (isSPANavigation && listeningOnEngagement) {
triggerEngagement()
currentDocumentHeight = getDocumentHeight()
maxScrollDepthPx = getCurrentScrollDepthPx()
}
{{/if}}

lastPage = location.pathname
trigger('pageview')
Expand Down Expand Up @@ -345,12 +355,14 @@
page()
}

{{#if pageleave}}
window.addEventListener('pageshow', function(event) {
if (event.persisted) {
// Page was restored from bfcache - trigger a pageview
page();
}
})
{{/if}}
{{/unless}}

{{#if (any outbound_links file_downloads tagged_events)}}
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/engagement-hash-exclusions.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/engagement-hash-pageview-props.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/engagement-hash.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/engagement-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/engagement-pageview-props.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/engagement.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/scroll-depth-content-onscroll.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/scroll-depth-hash.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/scroll-depth-slow-window-load.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion tracker/test/fixtures/scroll-depth.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 7dd5664

Please sign in to comment.