@beworke/pixel 0.1.0-rc.1 → 0.1.0-rc.10

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.
Files changed (189) hide show
  1. package/CHANGELOG.md +303 -4
  2. package/README.md +90 -128
  3. package/RELEASE_CANDIDATE.md +218 -101
  4. package/dist/Pixel-BnN86r4X.d.ts +797 -0
  5. package/dist/Pixel-BoUGqCbP.d.mts +797 -0
  6. package/dist/{StorageFactory-CAkJJqVD.d.ts → StorageFactory-BfCArzMM.d.ts} +2 -2
  7. package/dist/{StorageFactory-BhpbB6Jj.d.mts → StorageFactory-C0prtNR7.d.mts} +2 -2
  8. package/dist/browser/index.cjs.js +3 -0
  9. package/dist/browser/index.cjs.js.map +1 -0
  10. package/dist/browser/index.d.mts +71 -0
  11. package/dist/browser/index.d.ts +71 -0
  12. package/dist/browser/index.esm.js +3 -0
  13. package/dist/browser/index.esm.js.map +1 -0
  14. package/dist/browser/pixel.buygoods-checkout.global.js +4 -0
  15. package/dist/browser/pixel.buygoods-checkout.global.js.map +1 -0
  16. package/dist/browser/pixel.buygoods-landing.global.js +4 -0
  17. package/dist/browser/pixel.buygoods-landing.global.js.map +1 -0
  18. package/dist/browser/pixel.global.js +4 -0
  19. package/dist/browser/pixel.global.js.map +1 -0
  20. package/dist/config/index.cjs.js +1 -1
  21. package/dist/config/index.cjs.js.map +1 -1
  22. package/dist/config/index.d.mts +16 -5
  23. package/dist/config/index.d.ts +16 -5
  24. package/dist/config/index.esm.js +1 -1
  25. package/dist/config/index.esm.js.map +1 -1
  26. package/dist/events/index.cjs.js +1 -1
  27. package/dist/events/index.cjs.js.map +1 -1
  28. package/dist/events/index.d.mts +2 -1
  29. package/dist/events/index.d.ts +2 -1
  30. package/dist/events/index.esm.js +1 -1
  31. package/dist/events/index.esm.js.map +1 -1
  32. package/dist/examples/html-script/README.md +21 -55
  33. package/dist/examples/html-script/RELEASE_CANDIDATE.md +39 -26
  34. package/dist/examples/html-script/add-payment-info/README.md +3 -3
  35. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-autocomplete.html +107 -96
  36. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-disabled.html +107 -96
  37. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-fields.html +106 -95
  38. package/dist/examples/html-script/add-payment-info/example-add-payment-info-data-track.html +114 -95
  39. package/dist/examples/html-script/add-payment-info/example-add-payment-info-dedupe.html +106 -95
  40. package/dist/examples/html-script/add-payment-info/example-add-payment-info-manual.html +97 -95
  41. package/dist/examples/html-script/add-payment-info/example-add-payment-info-rules-card.html +106 -95
  42. package/dist/examples/html-script/add-payment-info/example-add-payment-info-security.html +106 -95
  43. package/dist/examples/html-script/add-to-cart/README.md +9 -6
  44. package/dist/examples/html-script/add-to-cart/example-add-to-cart-attribute.html +133 -119
  45. package/dist/examples/html-script/add-to-cart/example-add-to-cart-auto.html +146 -130
  46. package/dist/examples/html-script/add-to-cart/example-add-to-cart-click.html +144 -127
  47. package/dist/examples/html-script/add-to-cart/example-add-to-cart-dedupe.html +133 -119
  48. package/dist/examples/html-script/add-to-cart/example-add-to-cart-link.html +590 -0
  49. package/dist/examples/html-script/add-to-cart/example-add-to-cart-manual.html +124 -116
  50. package/dist/examples/html-script/add-to-cart/example-add-to-cart-order-bump.html +133 -119
  51. package/dist/examples/html-script/add-to-cart/example-add-to-cart-text.html +147 -130
  52. package/dist/examples/html-script/behavior/example-behavior-engagement.html +489 -0
  53. package/dist/examples/html-script/behavior/example-behavior-heartbeat.html +350 -0
  54. package/dist/examples/html-script/behavior/example-behavior-runtime-intelligence.html +433 -0
  55. package/dist/examples/html-script/behavior/example-behavior-viewport.html +397 -0
  56. package/dist/examples/html-script/{example-behavior.html → behavior/example-behavior.html} +23 -17
  57. package/dist/examples/html-script/buygoods/example-buygoods-checkout.html +50 -0
  58. package/dist/examples/html-script/buygoods/ladding.html +184 -0
  59. package/dist/examples/html-script/example-basic.html +1 -1
  60. package/dist/examples/html-script/example-checkout-commerce.html +826 -0
  61. package/dist/examples/html-script/example-conversion.html +42 -49
  62. package/dist/examples/html-script/example-global-factory-classic.html +45 -0
  63. package/dist/examples/html-script/example-global-factory.html +40 -0
  64. package/dist/examples/html-script/example-integration.html +45 -51
  65. package/dist/examples/html-script/example-landing-commerce.html +416 -0
  66. package/dist/examples/html-script/example-runtime-diagnostics.html +108 -0
  67. package/dist/examples/html-script/example-transport.html +70 -63
  68. package/dist/examples/html-script/full-funnel/README.md +64 -0
  69. package/dist/examples/html-script/full-funnel/checkout.html +118 -0
  70. package/dist/examples/html-script/full-funnel/downsell.html +60 -0
  71. package/dist/examples/html-script/full-funnel/landing.html +153 -0
  72. package/dist/examples/html-script/full-funnel/thank-you.html +87 -0
  73. package/dist/examples/html-script/full-funnel/upsell.html +66 -0
  74. package/dist/examples/html-script/initiate-checkout/README.md +6 -6
  75. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-attribute.html +135 -122
  76. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-auto.html +143 -128
  77. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-click.html +144 -128
  78. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-manual.html +127 -120
  79. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-snapshot.html +136 -123
  80. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-submit.html +144 -131
  81. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-text.html +146 -130
  82. package/dist/examples/html-script/internal-checkout/example-cardioclear-checkout.html +103 -0
  83. package/dist/examples/html-script/internal-checkout/example-slimsoda-checkout.html +103 -0
  84. package/dist/examples/html-script/lead/README.md +9 -7
  85. package/dist/examples/html-script/lead/example-lead-trigger-attribute.html +107 -94
  86. package/dist/examples/html-script/lead/example-lead-trigger-auto.html +118 -103
  87. package/dist/examples/html-script/lead/example-lead-trigger-click.html +118 -102
  88. package/dist/examples/html-script/release-candidate.html +219 -107
  89. package/dist/examples/html-script/remove-from-cart/README.md +4 -4
  90. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-attribute.html +134 -121
  91. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-css.html +134 -121
  92. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-dedupe.html +141 -128
  93. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-manual.html +125 -118
  94. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-multi.html +135 -122
  95. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-state.html +136 -123
  96. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-text.html +139 -124
  97. package/dist/examples/html-script/search/README.md +1 -1
  98. package/dist/examples/html-script/search/example-search-attribute.html +107 -99
  99. package/dist/examples/html-script/search/example-search-button-sync.html +107 -99
  100. package/dist/examples/html-script/search/example-search-dedupe.html +107 -99
  101. package/dist/examples/html-script/search/example-search-input.html +108 -99
  102. package/dist/examples/html-script/search/example-search-manual.html +98 -96
  103. package/dist/examples/html-script/search/example-search-submit.html +107 -99
  104. package/dist/examples/html-script/search/example-search-text.html +112 -99
  105. package/dist/examples/html-script/url-context/example-url-context-allowed-domains.html +92 -0
  106. package/dist/examples/html-script/url-context/example-url-context-landing.html +110 -0
  107. package/dist/examples/html-script/url-context/example-url-context-upsell.html +105 -0
  108. package/dist/examples/html-script/url-context/example-url-context.html +205 -0
  109. package/dist/examples/html-script/view-content/README.md +1 -1
  110. package/dist/examples/html-script/view-content/example-view-content-attribute.html +126 -118
  111. package/dist/examples/html-script/view-content/example-view-content-css.html +126 -118
  112. package/dist/examples/html-script/view-content/example-view-content-dedupe.html +126 -118
  113. package/dist/examples/html-script/view-content/example-view-content-empty.html +126 -118
  114. package/dist/examples/html-script/view-content/example-view-content-manual.html +117 -115
  115. package/dist/examples/html-script/view-content/example-view-content-product-card.html +126 -118
  116. package/dist/examples/html-script/view-content/example-view-content-text.html +131 -121
  117. package/dist/examples/release-candidate/README.md +2 -1
  118. package/dist/examples/v2/README.md +16 -13
  119. package/dist/index-B8u_3PGG.d.ts +460 -0
  120. package/dist/index-BxT2d-TK.d.mts +460 -0
  121. package/dist/index.cjs.js +1 -1
  122. package/dist/index.cjs.js.map +1 -1
  123. package/dist/index.d.mts +23 -361
  124. package/dist/index.d.ts +23 -361
  125. package/dist/index.esm.js +1 -1
  126. package/dist/index.esm.js.map +1 -1
  127. package/dist/pixel-DNGbAN5C.d.ts +871 -0
  128. package/dist/pixel-_BSDpx4M.d.mts +871 -0
  129. package/dist/pixel-default-config-BMYaqs7i.d.ts +21 -0
  130. package/dist/pixel-default-config-DLRya1tl.d.mts +21 -0
  131. package/dist/pixel-settings-D-t9zQb4.d.ts +40 -0
  132. package/dist/pixel-settings-DGxl0MVm.d.mts +40 -0
  133. package/dist/runtime/index.cjs.js +1 -1
  134. package/dist/runtime/index.cjs.js.map +1 -1
  135. package/dist/runtime/index.d.mts +19 -26
  136. package/dist/runtime/index.d.ts +19 -26
  137. package/dist/runtime/index.esm.js +1 -1
  138. package/dist/runtime/index.esm.js.map +1 -1
  139. package/dist/services/index.cjs.js +1 -1
  140. package/dist/services/index.cjs.js.map +1 -1
  141. package/dist/services/index.d.mts +14 -6
  142. package/dist/services/index.d.ts +14 -6
  143. package/dist/services/index.esm.js +1 -1
  144. package/dist/services/index.esm.js.map +1 -1
  145. package/dist/types-B-Nzagpk.d.mts +19 -0
  146. package/dist/types-D0KVsgzs.d.mts +293 -0
  147. package/dist/types-D3kJ9bfT.d.ts +293 -0
  148. package/dist/types-Dfi9C49l.d.ts +19 -0
  149. package/dist/url-context-Ck2LK18V.d.mts +87 -0
  150. package/dist/url-context-Ck2LK18V.d.ts +87 -0
  151. package/dist/v2/global.global.js +1 -1
  152. package/dist/v2/global.global.js.map +1 -1
  153. package/dist/v2/index.cjs.js +1 -1
  154. package/dist/v2/index.cjs.js.map +1 -1
  155. package/dist/v2/index.d.mts +26 -6
  156. package/dist/v2/index.d.ts +26 -6
  157. package/dist/v2/index.esm.js +1 -1
  158. package/dist/v2/index.esm.js.map +1 -1
  159. package/docs/public/README.md +80 -0
  160. package/docs/public/api/exports.md +55 -0
  161. package/docs/public/api/pixel.md +86 -0
  162. package/docs/public/configuration/commerce.md +44 -0
  163. package/docs/public/configuration/modules.md +63 -0
  164. package/docs/public/configuration/overview.md +85 -0
  165. package/docs/public/configuration/transport.md +127 -0
  166. package/docs/public/events/catalog.md +67 -0
  167. package/docs/public/getting-started/installation.md +87 -0
  168. package/docs/public/getting-started/quick-start.md +142 -0
  169. package/docs/public/getting-started/react-nextjs.md +78 -0
  170. package/docs/public/getting-started/script-tag.md +94 -0
  171. package/docs/public/guides/funnel-checkout.md +52 -0
  172. package/docs/public/guides/funnel-downsell.md +53 -0
  173. package/docs/public/guides/funnel-full.md +64 -0
  174. package/docs/public/guides/funnel-landing.md +70 -0
  175. package/docs/public/guides/funnel-thank-you.md +48 -0
  176. package/docs/public/guides/funnel-upsell.md +72 -0
  177. package/docs/public/limitations.md +33 -0
  178. package/docs/public/privacy/limitations.md +33 -0
  179. package/docs/public/release-candidate/validation.md +42 -0
  180. package/docs/public/troubleshooting.md +56 -0
  181. package/package.json +38 -20
  182. package/dist/index-DUfFzniE.d.mts +0 -274
  183. package/dist/index-DUfFzniE.d.ts +0 -274
  184. package/dist/pixel-CbeF25mD.d.mts +0 -555
  185. package/dist/pixel-CbeF25mD.d.ts +0 -555
  186. package/dist/pixel-default-config-1VgLFOiL.d.mts +0 -5
  187. package/dist/pixel-default-config-Bxb-Vdd8.d.ts +0 -5
  188. package/dist/types-CTpRvFKZ.d.ts +0 -71
  189. package/dist/types-DGlBdsAy.d.mts +0 -71
@@ -0,0 +1,87 @@
1
+ # Instalação
2
+
3
+ ## Requisitos
4
+
5
+ - Node.js 18+ (para npm/ESM)
6
+ - Navegador moderno (Chrome, Firefox, Safari, Edge)
7
+
8
+ ## npm (registry — recomendado para o time)
9
+
10
+ Pacote **público** — **não precisa de token** nem login npm para instalar:
11
+
12
+ ```bash
13
+ npm install @beworke/pixel@rc
14
+ ```
15
+
16
+ Confirme a versão instalada:
17
+
18
+ ```bash
19
+ node -e "console.log(require('@beworke/pixel/package.json').version)"
20
+ ```
21
+
22
+ > Evite `npm install @beworke/pixel` sem tag até a tag `latest` apontar para a RC atual. Use `@rc`.
23
+
24
+ ## Onde ler a documentação
25
+
26
+ | Contexto | Caminho |
27
+ |----------|---------|
28
+ | **Browser (GitHub)** | https://github.com/techionext/Pixel-Global/tree/main/packages/pixel/docs/public |
29
+ | **Após npm install** | `node_modules/@beworke/pixel/docs/public/` |
30
+
31
+ O site **npmjs.com não abre** arquivos `.md` individuais (ex.: `npmjs.com/package/@beworke/docs/...` → 404). Isso é normal.
32
+
33
+ ## Tarball local (opcional)
34
+
35
+ ```bash
36
+ pnpm pack:pixel
37
+ npm install ./artifacts/beworke-pixel-<versão>.tgz
38
+ ```
39
+
40
+ A versão exata está em `package.json` / `artifacts/latest-package.json`.
41
+
42
+ ## Validar instalação limpa
43
+
44
+ Na raiz do monorepo:
45
+
46
+ ```bash
47
+ pnpm pack:pixel
48
+ pnpm validate:pixel-package
49
+ pnpm smoke:pixel-package
50
+ ```
51
+
52
+ O tarball fica em `artifacts/` (não use `pnpm --filter @beworke/pixel pack` como fluxo principal).
53
+
54
+ ## Imports recomendados
55
+
56
+ ```typescript
57
+ import { Pixel, createPixel, DEFAULT_PIXEL_CONFIG, type PixelConfig } from '@beworke/pixel';
58
+ import { bootstrapPixel } from '@beworke/pixel/browser';
59
+ ```
60
+
61
+ Subpaths adicionais: [Package exports](../api/exports.md).
62
+
63
+ ## CDN / script tag
64
+
65
+ ```html
66
+ <script src="https://unpkg.com/@beworke/pixel@rc/dist/browser/pixel.global.js"></script>
67
+ <script type="module">
68
+ const pixel = await Pixel({
69
+ ...Pixel.DEFAULT_PIXEL_CONFIG,
70
+ identity: { pixelId: 'pix_YOUR_ID' },
71
+ });
72
+ </script>
73
+ ```
74
+
75
+ Presets BuyGoods (um script, sem settings):
76
+
77
+ ```html
78
+ <script src="https://unpkg.com/@beworke/pixel@latest/dist/browser/pixel.buygoods-landing.global.js"></script>
79
+ <script src="https://unpkg.com/@beworke/pixel@latest/dist/browser/pixel.buygoods-checkout.global.js"></script>
80
+ ```
81
+
82
+ Detalhes: [Script tag](./script-tag.md).
83
+
84
+ ## O que não instalar
85
+
86
+ - Não importe de `src/` — use apenas exports do pacote publicados no tarball.
87
+ - Não dependa de `./diagnostics` — não é subpath público no `package.json` RC.
@@ -0,0 +1,142 @@
1
+ # Quick start
2
+
3
+ Há três níveis de uso. O input público é `PixelSettings`: somente
4
+ `identity.pixelId` é obrigatório. O SDK mescla o restante com
5
+ `DEFAULT_PIXEL_CONFIG` dentro do construtor de `Pixel`.
6
+
7
+ - objetos são mesclados profundamente;
8
+ - arrays substituem os defaults (não concatenam);
9
+ - `transport.sender` substitui a variante inteira (`test` / `internal` / `external`);
10
+ - `undefined` significa “usar o default”;
11
+ - `false`, `0` e `''` são valores válidos e não apagam o default por acidente.
12
+
13
+ Use `PixelSettings` no input e `PixelConfig` quando precisar da configuração
14
+ já resolvida.
15
+
16
+ ## 1. HTML — `Pixel(settings)`
17
+
18
+ O bundle global **não** auto-inicializa. Top-level `await` exige `type="module"`.
19
+
20
+ ```html
21
+ <script src="https://unpkg.com/@beworke/pixel@rc/dist/browser/pixel.global.js"></script>
22
+ <script type="module">
23
+ const pixel = await Pixel({
24
+ identity: {
25
+ pixelId: 'pix_YOUR_ID',
26
+ },
27
+ });
28
+ pixel.lead({ email: 'user@example.com' });
29
+ </script>
30
+ ```
31
+
32
+ Overrides opcionais:
33
+
34
+ ```js
35
+ await Pixel({
36
+ identity: { pixelId: 'pix_YOUR_ID' },
37
+ app: { environment: 'development', debug: true },
38
+ });
39
+ ```
40
+
41
+ Isso equivale a `bootstrapPixel(settings)`: uma instância por `window`.
42
+
43
+ ## 2. NPM — `createPixel`
44
+
45
+ Instâncias **independentes** (não é singleton).
46
+
47
+ ```typescript
48
+ import { createPixel } from '@beworke/pixel';
49
+
50
+ const pixel = await createPixel({
51
+ identity: { pixelId: 'pix_YOUR_ID' },
52
+ });
53
+ ```
54
+
55
+ A classe pública continua válida:
56
+
57
+ ```typescript
58
+ import { Pixel } from '@beworke/pixel';
59
+
60
+ const pixel = new Pixel({
61
+ identity: { pixelId: 'pix_YOUR_ID' },
62
+ });
63
+ await pixel.init();
64
+ ```
65
+
66
+ Um `PixelConfig` completo continua sendo aceito.
67
+
68
+ ## 3. Browser avançado — `bootstrapPixel`
69
+
70
+ ```typescript
71
+ import { bootstrapPixel } from '@beworke/pixel/browser';
72
+
73
+ const pixel = await bootstrapPixel(
74
+ {
75
+ identity: { pixelId: 'pix_YOUR_ID' },
76
+ },
77
+ { waitForConsent: () => true }
78
+ );
79
+ ```
80
+
81
+ - Sem `force`, a primeira chamada é dona da instância naquela `window`.
82
+ - Para trocar a configuração: `destroyBootstrappedPixel()` ou `{ force: true }`.
83
+ - Chamadas concorrentes compartilham a configuração da primeira chamada.
84
+
85
+ ## 4. Eventos automáticos
86
+
87
+ Após `Pixel(settings)` / `createPixel` / `bootstrapPixel`:
88
+
89
+ - `PAGE_VIEW` (core) é emitido por default
90
+ - métodos manuais de conversão (`lead`, `purchase`, …) estão habilitados
91
+ - AutoTrack escuta `[data-track="<evento>"]` no clique (`view_content`, `add_to_cart`, `remove_from_cart`, `initiate_checkout`, `add_payment_info`, `purchase`, `lead`, `search`)
92
+ - `view_content` dispara no **hover** e quando o elemento **fica visível**; `data-trigger="hover"` (ou `click` / `visible`) restringe o modo — sem o atributo, valem os 3
93
+ - enrichment de commerce está on: informe o catálogo para completar name/price/currency
94
+ - rules de DOM extras, behavior avançado e destinos Meta/Google/TikTok
95
+ continuam **desabilitados** até você habilitá-los
96
+
97
+ ```html
98
+ <button data-track="add_to_cart" data-product-id="sku-1">Comprar</button>
99
+ <div data-track="view_content" data-product-id="sku-1">Produto (click + hover + visible)</div>
100
+ <div data-track="view_content" data-product-id="sku-1" data-trigger="hover">Só hover</div>
101
+ <button data-track="lead" data-email="user@example.com">Quero saber mais</button>
102
+ ```
103
+
104
+ ## 5. Conversão manual
105
+
106
+ ```typescript
107
+ pixel.purchase({
108
+ transactionId: 'order_123',
109
+ value: 197,
110
+ currency: 'BRL',
111
+ });
112
+ ```
113
+
114
+ Outros métodos: `lead`, `addToCart`, `removeFromCart`, `initiateCheckout`, `addPaymentInfo`, `viewContent`, `search`.
115
+
116
+ ## 6. Encerrar (SPA / navegação)
117
+
118
+ ```typescript
119
+ await pixel.destroy();
120
+ ```
121
+
122
+ Com `bootstrapPixel` / `window.Pixel`, prefira `destroyBootstrappedPixel()` / `Pixel.destroy()`. Em React, o `PixelProvider` é dono do lifecycle.
123
+
124
+ ## 7. Debug (somente desenvolvimento)
125
+
126
+ ```typescript
127
+ if (pixel.isInitialized()) {
128
+ console.log(pixel.getDebugSnapshot());
129
+ }
130
+ ```
131
+
132
+ `getDebugSnapshot()` é público; não use `getDebugServices()` (interno).
133
+
134
+ `DEFAULT_PIXEL_CONFIG` permanece disponível para inspeção e configuração avançada — não é necessário espalhá-lo numa integração comum.
135
+
136
+ ## Próximos passos
137
+
138
+ - [Configuração](../configuration/overview.md)
139
+ - [Transport](../configuration/transport.md)
140
+ - [Catálogo de eventos](../events/catalog.md)
141
+ - [Funil checkout](../guides/funnel-checkout.md)
142
+ - [React / Next.js](./react-nextjs.md)
@@ -0,0 +1,78 @@
1
+ # React e Next.js (App Router)
2
+
3
+ O pacote recomendado é [`@beworke/pixel-react`](../../../../pixel-react/README.md): `PixelProvider` + `usePixel` sobre `bootstrapPixel`.
4
+
5
+ Esta camada **não** duplica `lead` / `purchase` no Context. O hook devolve a instância real de `Pixel`. O playground Next Bemony continua na integração de domínio e **não** usa este pacote genérico.
6
+
7
+ ## Instalação
8
+
9
+ ```bash
10
+ pnpm add @beworke/pixel-react@rc @beworke/pixel@rc
11
+ ```
12
+
13
+ ## Provider
14
+
15
+ ```tsx
16
+ 'use client';
17
+
18
+ import { PixelProvider } from '@beworke/pixel-react';
19
+ import type { PixelSettings } from '@beworke/pixel';
20
+
21
+ const settings = {
22
+ identity: { pixelId: 'pix_YOUR_ID' },
23
+ } satisfies PixelSettings;
24
+
25
+ export function Providers({ children }: { children: React.ReactNode }) {
26
+ return <PixelProvider settings={settings}>{children}</PixelProvider>;
27
+ }
28
+ ```
29
+
30
+ `settings` é `PixelSettings`. Somente `identity.pixelId` é obrigatório; o Core resolve o restante.
31
+
32
+ ## Hook
33
+
34
+ ```tsx
35
+ 'use client';
36
+
37
+ import { usePixel } from '@beworke/pixel-react';
38
+
39
+ export function LeadButton() {
40
+ const { pixel, ready, status, error } = usePixel();
41
+
42
+ if (status === 'initializing') {
43
+ return <span>Inicializando...</span>;
44
+ }
45
+
46
+ if (error) {
47
+ return <span>Falha ao inicializar o Pixel.</span>;
48
+ }
49
+
50
+ return (
51
+ <button
52
+ disabled={!ready}
53
+ onClick={() => {
54
+ pixel?.lead({ email: 'user@example.com' });
55
+ }}
56
+ >
57
+ Enviar lead
58
+ </button>
59
+ );
60
+ }
61
+ ```
62
+
63
+ ## SSR
64
+
65
+ - `PixelProvider` é Client Component (`'use client'`).
66
+ - O `layout.tsx` pode permanecer Server Component.
67
+ - Importar o pacote não acessa `window`.
68
+ - Bootstrap só no `useEffect` do cliente.
69
+
70
+ ## Strict Mode e múltiplos Providers
71
+
72
+ Vários Providers na mesma `window` compartilham a instância. Strict Mode (mount → cleanup → mount) não destrói a instância reutilizada; o último unmount real destrói o bootstrap.
73
+
74
+ `settings` é capturado na montagem. Reinit dinâmico está fora do MVP.
75
+
76
+ ## Alternativa: instância local
77
+
78
+ Apps que precisam de uma instância isolada (sem singleton da `window`) podem continuar usando `createPixel` ou `new Pixel(settings)` num `useEffect` próprio. Nesse caso o app é dono de `destroy()`.
@@ -0,0 +1,94 @@
1
+ # Script tag (IIFE / global)
2
+
3
+ ## Build
4
+
5
+ O subpath `@beworke/pixel/global` expõe um bundle IIFE autossuficiente.
6
+
7
+ Após o build, o artefato recomendado é `dist/browser/pixel.global.js`. O bundle legado `dist/v2/global.global.js` (`window.PixelV2`) permanece para compatibilidade.
8
+
9
+ Carregar o script **apenas registra** a API. Não há auto-init, leitura de `document.currentScript` nem atributos `data-*`.
10
+
11
+ ## Presets BuyGoods (sem configuração)
12
+
13
+ Para landing e checkout BuyGoods o integrador **só inclui o script**. `pixelId`, `subid4`, UTMs e detectores já vêm internos.
14
+
15
+ ```html
16
+ <!-- Landing: gera subid4 e decora todos os links -->
17
+ <script src="https://unpkg.com/@beworke/pixel@latest/dist/browser/pixel.buygoods-landing.global.js"></script>
18
+
19
+ <!-- Checkout: lê subid4, ATC, ADD_PAYMENT_INFO, heartbeat (sobe para window.top) -->
20
+ <script src="https://unpkg.com/@beworke/pixel@latest/dist/browser/pixel.buygoods-checkout.global.js"></script>
21
+ ```
22
+
23
+ Não chame `Pixel({...})` nessas páginas. O preset auto-inicializa.
24
+
25
+ ## HTML mínimo (`type="module"`)
26
+
27
+ Top-level `await` exige `type="module"`.
28
+
29
+ ```html
30
+ <!DOCTYPE html>
31
+ <html lang="pt-BR">
32
+ <head>
33
+ <meta charset="UTF-8" />
34
+ <title>Pixel — script tag</title>
35
+ <script src="https://unpkg.com/@beworke/pixel@rc/dist/browser/pixel.global.js"></script>
36
+ </head>
37
+ <body>
38
+ <button id="lead-button" type="button">Enviar lead</button>
39
+ <script type="module">
40
+ const pixel = await Pixel({
41
+ identity: { pixelId: 'pix_YOUR_ID' },
42
+ });
43
+
44
+ document.getElementById('lead-button').addEventListener('click', () => {
45
+ pixel.lead({ email: 'user@example.com' });
46
+ });
47
+ </script>
48
+ </body>
49
+ </html>
50
+ ```
51
+
52
+ ## Script clássico (sem top-level await)
53
+
54
+ ```html
55
+ <script>
56
+ Pixel({
57
+ identity: {
58
+ pixelId: 'pix_YOUR_ID',
59
+ },
60
+ })
61
+ .then(function (pixel) {
62
+ pixel.lead({ email: 'user@example.com' });
63
+ })
64
+ .catch(function (error) {
65
+ console.error(error);
66
+ });
67
+ </script>
68
+ ```
69
+
70
+ ## API global
71
+
72
+ ```js
73
+ await Pixel(settings); // bootstrap (uma instância por window)
74
+ await Pixel.create(settings); // instância independente
75
+ await Pixel.bootstrap(settings, { force: true, waitForConsent });
76
+ Pixel.getInstance();
77
+ Pixel.getPending();
78
+ await Pixel.destroy();
79
+ new Pixel.Client(settings); // classe; o construtor resolve PixelSettings
80
+ Pixel.DEFAULT_PIXEL_CONFIG; // inspeção / configuração avançada
81
+ ```
82
+
83
+ `window.PixelV2` continua como compatibilidade / baixo nível (`Pixel`, `DEFAULT_PIXEL_CONFIG`, `resolveStorageAdapterName`, `createPixel`, `bootstrap`, `getInstance`, `destroy`).
84
+
85
+ ## Exemplos no monorepo
86
+
87
+ - `apps/playground-html/example-global-factory.html`
88
+ - `apps/playground-html/example-global-factory-classic.html`
89
+
90
+ ## Limitações
91
+
92
+ - TypeScript/IDE não inferem tipos no global — use JSDoc ou migre para npm ESM em apps maiores.
93
+ - A aplicação controla **quando** chamar `Pixel(settings)` após consentimento.
94
+ - Não declare conformidade LGPD/GDPR/CCPA apenas por usar este bundle.
@@ -0,0 +1,52 @@
1
+ # Funil — Checkout
2
+
3
+ ## Objetivo
4
+
5
+ Rastrear início de checkout, carrinho, pagamento e compra.
6
+
7
+ ## Config
8
+
9
+ - catálogo de produtos em `commerce.catalog` (enrichment já está on por default)
10
+ - `identity.checkoutId`, `funnelStepId`
11
+ - Transport API habilitado
12
+
13
+ Ver `apps/playground-next/lib/pixel-config.ts` e `apps/playground-html/public/html/checkout.html`.
14
+
15
+ ## API manual (ordem recomendada)
16
+
17
+ ```typescript
18
+ await pixel.init(); // PAGE_VIEW
19
+
20
+ pixel.addToCart({ productId: 'main' }); // opcional se carrinho já montado
21
+ pixel.initiateCheckout(); // início do checkout
22
+ pixel.addPaymentInfo({ paymentType: 'card' }); // antes de confirmar
23
+ pixel.purchase({ transactionId: 'ord_123' }); // após confirmação
24
+ ```
25
+
26
+ ## AutoTrack
27
+
28
+ `modules.conversion.auto.detectors` para `addToCart`, `initiateCheckout`, `purchase` com seletores `[data-track]`.
29
+
30
+ ## Eventos esperados
31
+
32
+ 1. `PAGE_VIEW`
33
+ 2. `ADD_TO_CART` (se aplicável)
34
+ 3. `INITIATE_CHECKOUT`
35
+ 4. `ADD_PAYMENT_INFO`
36
+ 5. `PURCHASE`
37
+
38
+ ## QA
39
+
40
+ - [ ] `value` / `currency` coerentes com `commerce.catalog`
41
+ - [ ] `transactionId` único por pedido
42
+ - [ ] Batch flush antes de redirect (aguardar rede ou `destroy()`)
43
+
44
+ ## Erros comuns
45
+
46
+ | Problema | Causa | Solução |
47
+ |----------|-------|---------|
48
+ | `PURCHASE` sem valor | Catálogo vazio | Preencher `commerce.catalog` ou passar `value` em `purchase()` |
49
+ | Eventos fora de ordem | Chamadas antes do `init()` | Aguardar `init()` |
50
+ | Perda no redirect | Navegação imediata | `await pixel.destroy()` ou delay curto |
51
+
52
+ Guia Next.js: [React / Next.js](../getting-started/react-nextjs.md)
@@ -0,0 +1,53 @@
1
+ # Funil — Downsell
2
+
3
+ ## Objetivo
4
+
5
+ Oferta alternativa (menor preço) quando upsell é recusado.
6
+
7
+ ## Importante (RC)
8
+
9
+ Sem evento `DOWNSELL_*`. Mesmo padrão do upsell:
10
+
11
+ - `PAGE_VIEW`
12
+ - `VIEW_CONTENT` — downsell apresentado
13
+ - `PURCHASE` — aceite
14
+
15
+ ## Config
16
+
17
+ ```typescript
18
+ identity: {
19
+ funnelStepId: 'downsell_step_01',
20
+ offerId: 'downsell_basic',
21
+ },
22
+ commerce: {
23
+ catalog: {
24
+ products: [
25
+ { id: 'downsell_01', name: 'Plano básico', type: 'downsell', price: 47, currency: 'BRL', quantity: 1 },
26
+ ],
27
+ },
28
+ },
29
+ ```
30
+
31
+ ## API manual
32
+
33
+ ```typescript
34
+ pixel.viewContent({ contentId: 'downsell_01' });
35
+
36
+ // Aceite
37
+ pixel.purchase({ transactionId: 'downsell_tx_789', value: 47, currency: 'BRL' });
38
+ ```
39
+
40
+ ## Eventos esperados
41
+
42
+ 1. `PAGE_VIEW`
43
+ 2. `VIEW_CONTENT`
44
+ 3. `PURCHASE` ou abandono
45
+
46
+ ## QA
47
+
48
+ - [ ] Step ID reflete posição no funil
49
+ - [ ] Valor menor que upsell/checkout refletido no payload
50
+
51
+ ## Erros comuns
52
+
53
+ Documentar downsell como `VIEW_CONTENT` + `PURCHASE` na spec interna — não esperar tipo dedicado na API HTTP legada.
@@ -0,0 +1,64 @@
1
+ # Funil completo
2
+
3
+ Fluxo de referência para landing → checkout → upsell → downsell → thank-you.
4
+
5
+ ## Ordem das páginas
6
+
7
+ ```txt
8
+ 1. Landing → PAGE_VIEW, behavior, LEAD (opcional)
9
+ 2. Checkout → INITIATE_CHECKOUT, ADD_PAYMENT_INFO, PURCHASE (principal)
10
+ 3. Upsell → VIEW_CONTENT, PURCHASE (opcional)
11
+ 4. Downsell → VIEW_CONTENT, PURCHASE (opcional)
12
+ 5. Thank-you → PAGE_VIEW, PURCHASE (confirmação/dedupe)
13
+ ```
14
+
15
+ ## Identity por etapa
16
+
17
+ Atualize em cada página (ou no router):
18
+
19
+ | Campo | Exemplo |
20
+ |-------|---------|
21
+ | `funnelId` | Constante do funil |
22
+ | `funnelStepId` | `landing`, `checkout`, `upsell`, … |
23
+ | `pageId` | ID da página no CMS |
24
+ | `offerId` | Oferta ativa |
25
+
26
+ ## Persistência cross-page
27
+
28
+ ```typescript
29
+ storage: {
30
+ persistence: {
31
+ visitor: 'localStorage',
32
+ session: 'sessionStorage',
33
+ attribution: 'localStorage',
34
+ },
35
+ },
36
+ ```
37
+
38
+ Visitor e sessão devem continuar entre steps no mesmo domínio.
39
+
40
+ ## Commerce
41
+
42
+ Um `catalog` com todos os produtos (main, bumps, upsell, downsell) simplifica enrichment. Filtre por `productId` nas chamadas manuais.
43
+
44
+ ## Transport
45
+
46
+ Uma instância `Pixel` por aba; `destroy()` ao desmontar componentes React entre rotas se recriar instância.
47
+
48
+ ## QA end-to-end
49
+
50
+ 1. Instalar tarball RC em app limpo
51
+ 2. Percorrer funil completo em staging
52
+ 3. Validar sequência na API backend
53
+ 4. Confirmar attribution (UTM) na primeira landing
54
+ 5. Verificar dedupe de `PURCHASE` duplicado na thank-you
55
+
56
+ ## Exemplos
57
+
58
+ | Etapa | Exemplo |
59
+ |-------|---------|
60
+ | Landing | `apps/playground-html/public/html/landing.html` |
61
+ | Checkout | `apps/playground-html/public/html/checkout.html` |
62
+ | Full (Next) | `apps/playground-next/` |
63
+
64
+ Guias individuais: [landing](./funnel-landing.md), [checkout](./funnel-checkout.md), [upsell](./funnel-upsell.md), [downsell](./funnel-downsell.md), [thank-you](./funnel-thank-you.md).
@@ -0,0 +1,70 @@
1
+ # Funil — Landing
2
+
3
+ ## Objetivo
4
+
5
+ Medir visita, comportamento na página e leads antes do checkout.
6
+
7
+ ## Config recomendada
8
+
9
+ ```typescript
10
+ import { DEFAULT_TRANSPORT_CONFIG } from '@beworke/pixel/config';
11
+
12
+ transport: {
13
+ ...DEFAULT_TRANSPORT_CONFIG,
14
+ enabled: true,
15
+ sender: { mode: 'internal' },
16
+ },
17
+ modules: {
18
+ ...DEFAULT_PIXEL_CONFIG.modules,
19
+ core: { ...DEFAULT_PIXEL_CONFIG.modules.core, enabled: true },
20
+ behavior: {
21
+ ...DEFAULT_PIXEL_CONFIG.modules.behavior,
22
+ enabled: true,
23
+ trackers: {
24
+ scroll: { enabled: true, thresholds: [25, 50, 75, 100], debounceMs: 100 },
25
+ click: { enabled: true, rageClick: { enabled: true } },
26
+ visibility: { enabled: true },
27
+ exitIntent: { enabled: true },
28
+ },
29
+ },
30
+ },
31
+ ```
32
+
33
+ Ajuste `identity.funnelStepId` / `pageId` para a landing.
34
+
35
+ ## API manual
36
+
37
+ ```typescript
38
+ await pixel.init();
39
+ // PAGE_VIEW automático
40
+
41
+ pixel.lead({ email: 'user@example.com' }); // formulário enviado
42
+ pixel.viewContent({ contentId: 'hero-offer' }); // CTA / seção vista
43
+ ```
44
+
45
+ ## AutoTrack
46
+
47
+ Opcional: `modules.conversion.auto` + detector `lead` com seletores do formulário.
48
+
49
+ ## Eventos esperados (ordem típica)
50
+
51
+ 1. `PAGE_VIEW`
52
+ 2. `SCROLL`, `PAGE_CLICK`, … (behavior)
53
+ 3. `LEAD` ou `VIEW_CONTENT` (conversão)
54
+
55
+ ## QA
56
+
57
+ - [ ] `pixelId` e sender (`internal`/`external`) corretos
58
+ - [ ] Persistência `sessionStorage` para sessão
59
+ - [ ] Um único `init()` por aba
60
+ - [ ] `getDebugSnapshot()` mostra transport enviando (dev)
61
+
62
+ ## Erros comuns
63
+
64
+ | Problema | Causa | Solução |
65
+ |----------|-------|---------|
66
+ | Sem eventos na API | `transport.enabled: false` ou sender `test` | Habilitar Transport + sender `internal`/`external` |
67
+ | Sessão zera no reload | Sem `storage.persistence.session` | Configurar `sessionStorage` |
68
+ | Duplo `PAGE_VIEW` | Dois `init()` | Singleton / cleanup `destroy()` |
69
+
70
+ Exemplo: `apps/playground-html/public/html/landing.html`
@@ -0,0 +1,48 @@
1
+ # Funil — Thank-you
2
+
3
+ ## Objetivo
4
+
5
+ Confirmar compra concluída e encerrar sessão de tracking da jornada.
6
+
7
+ ## API manual
8
+
9
+ Se `PURCHASE` já foi enviado no checkout/upsell, thank-you pode ser apenas:
10
+
11
+ ```typescript
12
+ await pixel.init(); // PAGE_VIEW na página de obrigado
13
+ ```
14
+
15
+ Opcional — reforço com dados do pedido:
16
+
17
+ ```typescript
18
+ pixel.purchase({
19
+ transactionId: 'ord_123',
20
+ value: 197,
21
+ currency: 'BRL',
22
+ });
23
+ ```
24
+
25
+ O módulo de conversão deduplica eventos repetidos dentro da janela configurada (`modules.core.dedupe`).
26
+
27
+ ## AutoTrack
28
+
29
+ Detector `purchase` em URL patterns: `thank-you`, `success`, `order` (`modules.conversion.rules.urlPatterns`).
30
+
31
+ ## Eventos esperados
32
+
33
+ 1. `PAGE_VIEW`
34
+ 2. `PURCHASE` (se disparado manualmente ou via auto)
35
+ 3. `ENGAGEMENT_SUMMARY` / `BEHAVIOR_SESSION_SUMMARY` (se behavior + session summary habilitados no destroy)
36
+
37
+ ## QA
38
+
39
+ - [ ] `transactionId` igual ao pedido real
40
+ - [ ] Sem PII em plain text se política exigir hashing (Etapa 25)
41
+
42
+ ## Encerramento
43
+
44
+ ```typescript
45
+ await pixel.destroy();
46
+ ```
47
+
48
+ Em SPA, ao sair da thank-you page.