@funnel10x/tracking 1.4.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/gtm.html CHANGED
@@ -1,9 +1,45 @@
1
- <!-- @funnel10x/tracking@1.4.0: a tag do GTM (Custom HTML, em All Pages). Só se mudam a chave e, se a account tiver o proxy gerido do PostHog, o apiHost; uma versão nova é um ficheiro novo. -->
1
+ <!--
2
+ @funnel10x/tracking@2.1.0: a tag do GTM (Custom HTML, em All Pages, com a condição de consentimento do site, se ele tiver banner).
3
+ Num site com esta tag, a tag oficial do PostHog só existe como reserva (decisão 1 da A2c): outra tag Custom HTML, com a mesma chave, que dispara
4
+ só no evento personalizado f10x_tracking_failed, que esta empurra para o dataLayer, uma vez, quando o tag.js não carrega (o jsDelivr em baixo ou
5
+ bloqueado, um integrity que não bate) ou carrega e não arranca (o window.f10xTracking sem version). A receita está no README do pacote.
6
+ Só se mudam a chave, o apiHost (o proxy gerido da account, se o tiver), os checkoutHosts, os linkedDomains (o cross-domain, desligado com a
7
+ lista vazia) e, numa emergência, o sdkVersion (uma versão exacta do posthog-js); uma versão nova do pacote é um ficheiro novo.
8
+ O script do jsDelivr cria-se por código, com o onload e o onerror como propriedades: um atributo onload no HTML é um handler inline, que o GTM
9
+ copia ao recriar o script e que uma CSP com nonce não deixa correr. Um pedido pendurado conta como falhado ao fim de 10 s.
10
+ O evento vai para o window.dataLayer: num GTM com a data layer renomeada (o l= do snippet do GTM) a reserva não dispara, e o ponto 8 do
11
+ checklist do README apanha-o.
12
+ -->
2
13
  <script>
3
14
  window.f10xTracking = {
4
15
  key: '{{PostHog project key}}',
5
16
  apiHost: '',
6
- checkoutHosts: []
17
+ sdkVersion: '',
18
+ checkoutHosts: [],
19
+ linkedDomains: []
7
20
  }
21
+ ;(function () {
22
+ var timer
23
+ function failed() {
24
+ clearTimeout(timer)
25
+ if (window.__f10xTracking && window.__f10xTracking.version) {
26
+ window.f10xTracking = window.__f10xTracking
27
+ return
28
+ }
29
+ if (window.__f10xTrackingFailed) return
30
+ window.__f10xTrackingFailed = true
31
+ ;(window.dataLayer = window.dataLayer || []).push({ event: 'f10x_tracking_failed' })
32
+ }
33
+ var script = document.createElement('script')
34
+ script.src = 'https://cdn.jsdelivr.net/npm/@funnel10x/tracking@2.1.0/dist/tag.js'
35
+ script.integrity = 'sha384-rAsc1JEueGFQjq9sTrZc5NnKX006TA+0GdHVDRpZVdOHLtWH28a8fZV2HbwqEtRI'
36
+ script.crossOrigin = 'anonymous'
37
+ script.onload = function () {
38
+ clearTimeout(timer)
39
+ if (!(window.f10xTracking && window.f10xTracking.version)) failed()
40
+ }
41
+ script.onerror = failed
42
+ timer = setTimeout(failed, 10000)
43
+ document.head.appendChild(script)
44
+ })()
8
45
  </script>
9
- <script src="https://cdn.jsdelivr.net/npm/@funnel10x/tracking@1.4.0/dist/tag.js" integrity="sha384-UTBEFP06SUs6EqWR2bkYb7Rq6QEj2SWvMGpf1/3g4uhyNGYMzyucjjeHtYYoW/xD" crossorigin="anonymous"></script>
package/dist/index.d.ts CHANGED
@@ -3,8 +3,10 @@ import type { PostHog } from 'posthog-js'
3
3
  export interface TrackingOptions {
4
4
  /** The PostHog project key of the account (`phc_…`). */
5
5
  key: string
6
- /** Where events go: the proxy on the site's own domain (`/_t`) in a direct repo; PostHog US by default. */
6
+ /** Where events go: the proxy on the site's own domain (`/_t`) in a direct repo, the account's managed proxy in a tag; PostHog US by default. The SDK (`array.js`) loads from the same host's assets. */
7
7
  apiHost?: string
8
+ /** An exact posthog-js version (`1.438.9`), for an emergency only: without it the 1.x channel of the PostHog CDN loads, and updates itself like the official tag. */
9
+ sdkVersion?: string
8
10
  /** The `consent` of a direct site's `site.json`; without it there is no switch and the snippet runs. */
9
11
  consent?: boolean
10
12
  /** The version of the page being served (direct site). */
@@ -15,7 +17,15 @@ export interface TrackingOptions {
15
17
  checkoutHosts?: string[]
16
18
  /** Add the missing hidden fields to lead forms (default true). */
17
19
  addFields?: boolean
18
- /** posthog-js options on top of this package's. */
20
+ /**
21
+ * Linked domains for cross-domain tracking (off by default): hosts, or registrable domains that also cover their
22
+ * subdomains, as a list or a string separated by commas or spaces (an entry that is not a hostname, like
23
+ * `*.example.com`, is ignored with a console warning). Links and forms to them carry `_f10x` on click or submit, and
24
+ * an `_f10x` that arrives within 2 minutes links the visitor: the origin's person and session when the page has no
25
+ * PostHog identity yet, or `linked_distinct_id` on every event when it has one.
26
+ */
27
+ linkedDomains?: string[] | string
28
+ /** posthog-js options on top of this package's (turning a feature off on one site, tests). */
19
29
  posthog?: Record<string, unknown>
20
30
  }
21
31
 
@@ -28,12 +38,11 @@ export interface Tracking {
28
38
  onReady(fn: (ready: true) => void): void
29
39
  fields(): Record<string, string>
30
40
  capture(event: string, properties?: Record<string, unknown>): void
41
+ /** The PostHog instance once the SDK has loaded; the stub (which queues calls) until then. */
31
42
  posthog: PostHog | null
32
43
  }
33
44
 
34
45
  export const VERSION: string
35
46
  export const CONSENT_KEY: string
36
47
  export const ALLOWED_PARAMS: string[]
37
- export function cleanUrl(value: string, base?: string): string
38
- export function cleanEvent<T>(event: T, base?: string): T
39
48
  export function init(options: TrackingOptions): Tracking