File size: 5,035 Bytes
6778ee0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | import { test, expect } from '@playwright/test'
import { detect } from '../support/installation-support-playwright-wrappers'
import { initializePageDynamically } from '../support/initialize-page-dynamically'
test.describe('detector.js (tech recognition)', () => {
test('skips v1 snippet detection by default', async ({ page }, {
testId
}) => {
const { url } = await initializePageDynamically(page, {
testId,
response: /* HTML */ `
<html>
<head>
<script src="" data-domain=""></script>
</head>
</html>
`
})
const result = await detect(page, {
url: url,
detectV1: false,
timeoutMs: 1000
})
expect(result.data.v1Detected).toBe(null)
})
test('detects WP plugin, WP and GTM', async ({ page }, { testId }) => {
const { url } = await initializePageDynamically(page, {
testId,
response: /* HTML */ `
<html>
<head>
<link
rel="icon"
href="https://example.com/wp-content/uploads/favicon.ico"
sizes="32x32"
/>
<meta name="plausible-analytics-version" content="2.3.1" />
<script
async
src="https://www.googletagmanager.com/gtm.js?id=GTM-123"
></script>
</head>
</html>
`
})
const result = await detect(page, {
url: url,
detectV1: false,
timeoutMs: 1000
})
expect(result.data.wordpressPlugin).toBe(true)
expect(result.data.wordpressLikely).toBe(true)
expect(result.data.gtmLikely).toBe(true)
})
test('No WP plugin, WP or GTM', async ({ page }, { testId }) => {
const { url } = await initializePageDynamically(page, {
testId,
response: /* HTML */ `<html>
<head></head>
</html>`
})
const result = await detect(page, {
url: url,
detectV1: false,
timeoutMs: 1000
})
expect(result.data.wordpressPlugin).toBe(false)
expect(result.data.wordpressLikely).toBe(false)
expect(result.data.gtmLikely).toBe(false)
expect(result.data.npm).toBe(false)
})
test('npm is reported correctly', async ({ page }, { testId }) => {
const { url } = await initializePageDynamically(page, {
testId,
scriptConfig: /* HTML */ `<script type="module">
import { init } from '/tracker/js/npm_package/plausible.js'
init({ domain: 'abc.de' })
</script>`
})
const result = await detect(page, { url: url, detectV1: false })
expect(result.data.wordpressPlugin).toBe(false)
expect(result.data.wordpressLikely).toBe(false)
expect(result.data.gtmLikely).toBe(false)
expect(result.data.npm).toBe(true)
})
})
test.describe('detector.js (v1 detection)', () => {
test('v1Detected is true when v1 plausible exists + detects WP plugin, WP and GTM', async ({
page
}, { testId }) => {
const { url } = await initializePageDynamically(page, {
testId,
response: /* HTML */ `
<html>
<head>
<link
rel="icon"
href="https://example.com/wp-content/uploads/favicon.ico"
sizes="32x32"
/>
<meta name="plausible-analytics-version" content="2.3.1" />
<script
async
src="https://www.googletagmanager.com/gtm.js?id=GTM-123"
></script>
<script
async
src="/tracker/js/plausible.local.manual.js"
data-domain="abc.de"
></script>
</head>
</html>
`
})
const result = await detect(page, {
url: url,
detectV1: true,
timeoutMs: 1000
})
expect(result.data.v1Detected).toBe(true)
expect(result.data.wordpressPlugin).toBe(true)
expect(result.data.wordpressLikely).toBe(true)
expect(result.data.gtmLikely).toBe(true)
expect(result.data.npm).toBe(false)
})
test('v1Detected is false when plausible function does not exist', async ({
page
}, { testId }) => {
const { url } = await initializePageDynamically(page, {
testId,
response: /* HTML */ `<html>
<head></head>
</html>`
})
const result = await detect(page, {
url: url,
detectV1: true,
timeoutMs: 1000
})
expect(result.data.v1Detected).toBe(false)
expect(result.data.wordpressPlugin).toBe(false)
expect(result.data.wordpressLikely).toBe(false)
expect(result.data.gtmLikely).toBe(false)
expect(result.data.npm).toBe(false)
})
test('v1Detected is false when v2 plausible installed', async ({ page }, {
testId
}) => {
const { url } = await initializePageDynamically(page, {
testId,
scriptConfig: {
domain: 'abc.de',
captureOnLocalhost: false
}
})
const result = await detect(page, {
url: url,
detectV1: true,
timeoutMs: 1000
})
expect(result.data.v1Detected).toBe(false)
})
})
|