Added the session recorder script to the Page protocol in the Infrastructure package.

This commit is contained in:
2026-08-13 01:19:19 +02:00
parent 3bcae4d789
commit 4bb3e9098c
2 changed files with 40 additions and 0 deletions
@@ -151,6 +151,34 @@ struct PageTests {
#expect(preconnect.lowerBound < script.lowerBound)
}
@Test
func `omits the session recorder script by default`() {
let html = StubPage(analytics: .init(
scriptURL: "https://analytics.example.com/script",
websiteID: "0000-website-id",
domains: "example.com"
)).render()
#expect(!html.contains("recorder.js"))
}
@Test
func `renders the session recorder script when recorder mode is on`() throws {
let html = StubPage(analytics: .init(
scriptURL: "https://analytics.example.com/script",
websiteID: "0000-website-id",
domains: "example.com",
recorder: true
)).render()
#expect(html.contains(#"<script defer src="https://analytics.example.com/recorder.js" data-website-id="0000-website-id"></script>"#))
let tracker = try #require(html.range(of: #"<script defer src="https://analytics.example.com/script""#))
let recorder = try #require(html.range(of: #"<script defer src="https://analytics.example.com/recorder.js""#))
#expect(tracker.lowerBound < recorder.lowerBound)
}
@Test
func `omits the analytics behavior flags that are disabled`() {
let html = StubPage(analytics: .init(