-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Average Scroll Depth Metric: extracted tracker changes (#4826)
* (cherry-pick) implement scroll depth tracking under pageleave variant * drop unnecessary vars * remove unused require * add scroll depth tests * improve error messages in test util * reevaluate currentDocumentHeight on page load * account for dynamically loaded content when initializing documnent height * remove all semicolons from tracker specs * allow window and document globals in tracker eslint * tweak global tracker dir eslint rules * update comment * reevaluate document height on scroll * add test * remove unneccessary timeout
- Loading branch information
1 parent
4d9ea15
commit 2a7d02b
Showing
20 changed files
with
402 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<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> | ||
</head> | ||
|
||
<body> | ||
<div id="main" style="height: 3000px; background-color: lightblue;"> | ||
<a id="navigate-away" href="/manual.html">Navigate away</a> | ||
</div> | ||
|
||
<script> | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const mainDiv = document.getElementById("main") | ||
let loadedMore = false | ||
|
||
window.addEventListener("scroll", () => { | ||
if (!loadedMore && window.innerHeight + window.scrollY >= document.body.offsetHeight) { | ||
loadedMore = true | ||
|
||
const newDiv = document.createElement("div") | ||
newDiv.setAttribute("id", "more-content") | ||
newDiv.setAttribute("style", "height: 2000px; background-color: lightcoral;") | ||
document.body.appendChild(newDiv); | ||
} | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
tracker/test/fixtures/scroll-depth-dynamic-content-load.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<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> | ||
</head> | ||
<body> | ||
<br> | ||
<div id="content"></div> | ||
<script> | ||
setTimeout(() => { | ||
document.getElementById('content').innerHTML = | ||
` | ||
<div style="height: 5000px; background-color: gray;"> | ||
<a id="navigate-away" href="/manual.html"> | ||
Navigate away | ||
</a> | ||
</div> | ||
` | ||
}, 500) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<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> | ||
</head> | ||
|
||
<body> | ||
<nav> | ||
<a id="home-link" href="#home">Home</a> | ||
<a id="about-link" href="#about">About</a> | ||
</nav> | ||
|
||
<div id="content"></div> | ||
|
||
<script> | ||
const routes = { | ||
'#home': '<h1>Home</h1><p>Welcome to the Home page!</p>', | ||
'#about': '<h1>About</h1><p style="height: 2000px;">Learn more about us here</p>', | ||
}; | ||
|
||
function loadContent() { | ||
const hash = window.location.hash || '#home'; | ||
const content = routes[hash] | ||
document.getElementById('content').innerHTML = content; | ||
} | ||
|
||
window.addEventListener('hashchange', loadContent); | ||
window.addEventListener('DOMContentLoaded', loadContent); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<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> | ||
</head> | ||
<body> | ||
<a id="navigate-away" href="/manual.html"> | ||
Navigate away | ||
</a> | ||
<br> | ||
<img id="slow-image" src="/img/slow-image" alt="slow image"> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<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> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div style="height: 5000px; background: repeating-linear-gradient(white, gray 500px);"> | ||
<a id="navigate-away" href="/manual.html">Navigate away</a> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
const { mockRequest } = require('./support/test-utils') | ||
const { expect, test } = require('@playwright/test'); | ||
const { expect, test } = require('@playwright/test') | ||
|
||
test.describe('combination of hash and exclusions script extensions', () => { | ||
test('excludes by hash part of the URL', async ({ page }) => { | ||
const plausibleRequestMock = mockRequest(page, '/api/event') | ||
|
||
await page.goto('/hash-exclusions.html#this/hash/should/be/ignored'); | ||
await page.goto('/hash-exclusions.html#this/hash/should/be/ignored') | ||
|
||
expect(await plausibleRequestMock, "should not have sent event").toBeNull() | ||
}); | ||
}); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.