File size: 1,222 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
import { waitForPlausibleFunction } from './wait-for-plausible-function'
import { checkWordPress } from './check-wordpress'
import { checkGTM } from './check-gtm'
import { checkNPM } from './check-npm'

window.scanPageBeforePlausibleInstallation = async function ({
  detectV1,
  debug,
  timeoutMs
}) {
  function log(message) {
    if (debug) console.log('[Plausible Verification]', message)
  }

  let v1Detected = null

  if (detectV1) {
    log('Waiting for Plausible function...')
    const plausibleFound = await waitForPlausibleFunction(timeoutMs)
    log(`plausibleFound: ${plausibleFound}`)
    v1Detected = plausibleFound && typeof window.plausible.s === 'undefined'
    log(`v1Detected: ${v1Detected}`)
  }

  const { wordpressPlugin, wordpressLikely } = checkWordPress(document)
  log(`wordpressPlugin: ${wordpressPlugin}`)
  log(`wordpressLikely: ${wordpressLikely}`)

  const gtmLikely = checkGTM(document)
  log(`gtmLikely: ${gtmLikely}`)

  const npm = checkNPM(document)
  log(`npm: ${npm}`)

  return {
    data: {
      completed: true,
      v1Detected: v1Detected,
      wordpressPlugin: wordpressPlugin,
      wordpressLikely: wordpressLikely,
      gtmLikely: gtmLikely,
      npm: npm
    }
  }
}