@beworke/pixel 0.1.0-rc.7 → 0.1.0-rc.8

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 (150) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +71 -56
  3. package/RELEASE_CANDIDATE.md +28 -62
  4. package/dist/Pixel-CCgGk43j.d.ts +797 -0
  5. package/dist/Pixel-CqbgC_72.d.mts +797 -0
  6. package/dist/{StorageFactory-DeMaZ8wk.d.ts → StorageFactory-BRBsnnH7.d.ts} +1 -1
  7. package/dist/{StorageFactory-Cq29vF32.d.mts → StorageFactory-Dp19Wecr.d.mts} +1 -1
  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 +55 -0
  11. package/dist/browser/index.d.ts +55 -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.global.js +4 -0
  15. package/dist/browser/pixel.global.js.map +1 -0
  16. package/dist/config/index.cjs.js +1 -1
  17. package/dist/config/index.cjs.js.map +1 -1
  18. package/dist/config/index.d.mts +15 -5
  19. package/dist/config/index.d.ts +15 -5
  20. package/dist/config/index.esm.js +1 -1
  21. package/dist/config/index.esm.js.map +1 -1
  22. package/dist/examples/html-script/RELEASE_CANDIDATE.md +6 -8
  23. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-autocomplete.html +40 -47
  24. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-disabled.html +40 -47
  25. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-fields.html +40 -47
  26. package/dist/examples/html-script/add-payment-info/example-add-payment-info-data-track.html +40 -47
  27. package/dist/examples/html-script/add-payment-info/example-add-payment-info-dedupe.html +40 -47
  28. package/dist/examples/html-script/add-payment-info/example-add-payment-info-manual.html +40 -47
  29. package/dist/examples/html-script/add-payment-info/example-add-payment-info-rules-card.html +40 -47
  30. package/dist/examples/html-script/add-payment-info/example-add-payment-info-security.html +40 -47
  31. package/dist/examples/html-script/add-to-cart/example-add-to-cart-attribute.html +40 -47
  32. package/dist/examples/html-script/add-to-cart/example-add-to-cart-auto.html +40 -47
  33. package/dist/examples/html-script/add-to-cart/example-add-to-cart-click.html +40 -47
  34. package/dist/examples/html-script/add-to-cart/example-add-to-cart-dedupe.html +40 -47
  35. package/dist/examples/html-script/add-to-cart/example-add-to-cart-link.html +40 -47
  36. package/dist/examples/html-script/add-to-cart/example-add-to-cart-manual.html +40 -47
  37. package/dist/examples/html-script/add-to-cart/example-add-to-cart-order-bump.html +40 -47
  38. package/dist/examples/html-script/add-to-cart/example-add-to-cart-text.html +40 -47
  39. package/dist/examples/html-script/behavior/example-behavior-engagement.html +4 -4
  40. package/dist/examples/html-script/behavior/example-behavior-heartbeat.html +4 -4
  41. package/dist/examples/html-script/behavior/example-behavior-runtime-intelligence.html +4 -4
  42. package/dist/examples/html-script/behavior/example-behavior-viewport.html +4 -4
  43. package/dist/examples/html-script/buygoods/example-buygoods-checkout.html +83 -0
  44. package/dist/examples/html-script/example-checkout-commerce.html +31 -30
  45. package/dist/examples/html-script/example-conversion.html +41 -48
  46. package/dist/examples/html-script/example-global-factory-classic.html +45 -0
  47. package/dist/examples/html-script/example-global-factory.html +40 -0
  48. package/dist/examples/html-script/example-integration.html +39 -45
  49. package/dist/examples/html-script/example-landing-commerce.html +3 -8
  50. package/dist/examples/html-script/example-runtime-diagnostics.html +4 -4
  51. package/dist/examples/html-script/example-transport.html +59 -57
  52. package/dist/examples/html-script/full-funnel/checkout.html +3 -1
  53. package/dist/examples/html-script/full-funnel/downsell.html +3 -1
  54. package/dist/examples/html-script/full-funnel/landing.html +3 -1
  55. package/dist/examples/html-script/full-funnel/thank-you.html +3 -1
  56. package/dist/examples/html-script/full-funnel/upsell.html +3 -1
  57. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-attribute.html +40 -47
  58. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-auto.html +40 -47
  59. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-click.html +40 -47
  60. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-manual.html +40 -47
  61. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-snapshot.html +40 -47
  62. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-submit.html +40 -47
  63. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-text.html +40 -47
  64. package/dist/examples/html-script/lead/example-lead-trigger-attribute.html +40 -47
  65. package/dist/examples/html-script/lead/example-lead-trigger-auto.html +40 -47
  66. package/dist/examples/html-script/lead/example-lead-trigger-click.html +40 -47
  67. package/dist/examples/html-script/release-candidate.html +31 -30
  68. package/dist/examples/html-script/remove-from-cart/README.md +3 -3
  69. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-attribute.html +40 -47
  70. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-css.html +40 -47
  71. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-dedupe.html +47 -54
  72. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-manual.html +40 -47
  73. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-multi.html +40 -47
  74. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-state.html +40 -47
  75. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-text.html +40 -47
  76. package/dist/examples/html-script/search/example-search-attribute.html +40 -47
  77. package/dist/examples/html-script/search/example-search-button-sync.html +40 -47
  78. package/dist/examples/html-script/search/example-search-dedupe.html +40 -47
  79. package/dist/examples/html-script/search/example-search-input.html +40 -47
  80. package/dist/examples/html-script/search/example-search-manual.html +40 -47
  81. package/dist/examples/html-script/search/example-search-submit.html +40 -47
  82. package/dist/examples/html-script/search/example-search-text.html +40 -47
  83. package/dist/examples/html-script/url-context/example-url-context-allowed-domains.html +4 -4
  84. package/dist/examples/html-script/url-context/example-url-context-landing.html +4 -4
  85. package/dist/examples/html-script/url-context/example-url-context-upsell.html +4 -4
  86. package/dist/examples/html-script/url-context/example-url-context.html +4 -4
  87. package/dist/examples/html-script/view-content/example-view-content-attribute.html +40 -47
  88. package/dist/examples/html-script/view-content/example-view-content-css.html +40 -47
  89. package/dist/examples/html-script/view-content/example-view-content-dedupe.html +40 -47
  90. package/dist/examples/html-script/view-content/example-view-content-empty.html +40 -47
  91. package/dist/examples/html-script/view-content/example-view-content-manual.html +40 -47
  92. package/dist/examples/html-script/view-content/example-view-content-product-card.html +40 -47
  93. package/dist/examples/html-script/view-content/example-view-content-text.html +40 -47
  94. package/dist/index.cjs.js +1 -1
  95. package/dist/index.cjs.js.map +1 -1
  96. package/dist/index.d.mts +8 -6
  97. package/dist/index.d.ts +8 -6
  98. package/dist/index.esm.js +1 -1
  99. package/dist/index.esm.js.map +1 -1
  100. package/dist/{pixel-DMwpppf_.d.mts → pixel-C93c-0M2.d.mts} +109 -97
  101. package/dist/{pixel-2uL4LSyC.d.ts → pixel-DVy4rzj8.d.ts} +109 -97
  102. package/dist/pixel-default-config-BkAjriVH.d.mts +21 -0
  103. package/dist/pixel-default-config-Co69vDP3.d.ts +21 -0
  104. package/dist/pixel-settings-BhfJqA92.d.mts +40 -0
  105. package/dist/pixel-settings-C0qPFTii.d.ts +40 -0
  106. package/dist/runtime/index.cjs.js +1 -1
  107. package/dist/runtime/index.cjs.js.map +1 -1
  108. package/dist/runtime/index.d.mts +4 -4
  109. package/dist/runtime/index.d.ts +4 -4
  110. package/dist/runtime/index.esm.js +1 -1
  111. package/dist/runtime/index.esm.js.map +1 -1
  112. package/dist/services/index.cjs.js +1 -1
  113. package/dist/services/index.cjs.js.map +1 -1
  114. package/dist/services/index.d.mts +4 -4
  115. package/dist/services/index.d.ts +4 -4
  116. package/dist/services/index.esm.js +1 -1
  117. package/dist/services/index.esm.js.map +1 -1
  118. package/dist/{types-BqUEoZo0.d.ts → types-B2aUNHb3.d.ts} +2 -2
  119. package/dist/{types-6HF3UlsL.d.mts → types-C0J9KUQg.d.mts} +2 -2
  120. package/dist/{types-CgrabttM.d.mts → types-C2dsBog1.d.mts} +1 -1
  121. package/dist/{types-fFcQ1apy.d.ts → types-DcaBYgVI.d.ts} +1 -1
  122. package/dist/v2/global.global.js +1 -1
  123. package/dist/v2/global.global.js.map +1 -1
  124. package/dist/v2/index.cjs.js +1 -1
  125. package/dist/v2/index.cjs.js.map +1 -1
  126. package/dist/v2/index.d.mts +21 -787
  127. package/dist/v2/index.d.ts +21 -787
  128. package/dist/v2/index.esm.js +1 -1
  129. package/dist/v2/index.esm.js.map +1 -1
  130. package/docs/public/README.md +7 -4
  131. package/docs/public/api/exports.md +12 -8
  132. package/docs/public/api/pixel.md +27 -6
  133. package/docs/public/configuration/commerce.md +2 -2
  134. package/docs/public/configuration/modules.md +11 -14
  135. package/docs/public/configuration/overview.md +41 -25
  136. package/docs/public/configuration/transport.md +127 -0
  137. package/docs/public/events/catalog.md +3 -1
  138. package/docs/public/getting-started/installation.md +14 -12
  139. package/docs/public/getting-started/quick-start.md +95 -30
  140. package/docs/public/getting-started/react-nextjs.md +57 -34
  141. package/docs/public/getting-started/script-tag.md +55 -32
  142. package/docs/public/guides/funnel-checkout.md +1 -1
  143. package/docs/public/guides/funnel-landing.md +9 -7
  144. package/docs/public/limitations.md +5 -4
  145. package/docs/public/privacy/limitations.md +6 -6
  146. package/docs/public/release-candidate/validation.md +4 -4
  147. package/docs/public/troubleshooting.md +7 -6
  148. package/package.json +8 -3
  149. package/dist/pixel-default-config-BDPUVHse.d.ts +0 -5
  150. package/dist/pixel-default-config-C5uLt52W.d.mts +0 -5
@@ -2,7 +2,9 @@
2
2
 
3
3
  Documentação para desenvolvedores que implementam funis e páginas com `@beworke/pixel`.
4
4
 
5
- **Versão de referência:** `0.1.0-rc.6` · **Etapas concluídas:** 1–20
5
+ A versão publicada está em `package.json` do pacote. Instale `@beworke/pixel@rc`.
6
+
7
+ > Esta pasta é a documentação **pública**. Arquitetura interna, prompts de etapas e relatórios de engenharia ficam em `PLAN_PIXEL/` (`ARCHITECTURE.md`, `PIXEL_V2_*`).
6
8
 
7
9
  > Esta pasta é a documentação **pública**. Arquitetura interna, prompts de etapas e relatórios de engenharia ficam em `PLAN_PIXEL/` (`ARCHITECTURE.md`, `PIXEL_V2_*`).
8
10
 
@@ -21,9 +23,9 @@ Instalação: `npm install @beworke/pixel@rc` (público, sem token).
21
23
  | Guia | Descrição |
22
24
  |------|-----------|
23
25
  | [Instalação](./getting-started/installation.md) | npm, tarball local, validação do pacote |
24
- | [Quick start](./getting-started/quick-start.md) | Primeiro `init` em ESM/CJS |
25
- | [Script tag (IIFE)](./getting-started/script-tag.md) | `@beworke/pixel/global` → `window.PixelV2` |
26
- | [React / Next.js](./getting-started/react-nextjs.md) | Padrão `useEffect` + hooks locais |
26
+ | [Quick start](./getting-started/quick-start.md) | Factory, classe e bootstrap |
27
+ | [Script tag (IIFE)](./getting-started/script-tag.md) | `@beworke/pixel/global` → `window.Pixel` |
28
+ | [React / Next.js](./getting-started/react-nextjs.md) | `@beworke/pixel-react` (`PixelProvider` / `usePixel`) |
27
29
 
28
30
  ## Referência
29
31
 
@@ -33,6 +35,7 @@ Instalação: `npm install @beworke/pixel@rc` (público, sem token).
33
35
  | [Package exports](./api/exports.md) | Subpaths do `package.json` |
34
36
  | [Catálogo de eventos](./events/catalog.md) | Tipos `PixelEvent` por categoria |
35
37
  | [Configuração — visão geral](./configuration/overview.md) | `PixelConfig` e defaults |
38
+ | [Transport](./configuration/transport.md) | Config única e senders `test`, `internal`, `external` |
36
39
  | [Módulos](./configuration/modules.md) | `modules.core`, `behavior`, `conversion`, etc. |
37
40
  | [Commerce (root)](./configuration/commerce.md) | `commerce.catalog`, `cart`, `enrichment` |
38
41
 
@@ -1,21 +1,24 @@
1
1
  # Package exports
2
2
 
3
- Auditado contra `package.json` do RC `0.1.0-rc.5`.
3
+ Auditado contra `package.json`. Não pinamos o número da RC neste documento.
4
4
 
5
5
  ## Entry principal
6
6
 
7
7
  | Subpath | Import | Conteúdo principal |
8
8
  |---------|--------|-------------------|
9
- | `@beworke/pixel` | ESM / CJS | `Pixel`, `DEFAULT_PIXEL_CONFIG`, `PixelConfig`, `PixelDebugSnapshot`, `resolveStorageAdapterName` |
9
+ | `@beworke/pixel` | ESM / CJS | `Pixel`, `createPixel`, `resolvePixelConfig`, `DEFAULT_PIXEL_CONFIG`, `PixelSettings`, `PixelConfig`, `PixelConfigurationError`, `PixelDebugSnapshot`, `resolveStorageAdapterName`, `SDK_VERSION` |
10
10
  | `@beworke/pixel/v2` | ESM / CJS | Alias do entry principal (mesmos exports) |
11
+ | `@beworke/pixel/browser` | ESM / CJS | `bootstrapPixel`, `getBootstrappedPixel`, `getBootstrappedPixelPending`, `destroyBootstrappedPixel`, `PixelBootstrapError` |
11
12
 
12
13
  ## Global (IIFE)
13
14
 
14
15
  | Subpath | Formato | Global |
15
16
  |---------|---------|--------|
16
- | `@beworke/pixel/global` | IIFE | `window.PixelV2` |
17
+ | `@beworke/pixel/global` | IIFE | `window.Pixel` (factory) + `window.PixelV2` (compat) |
17
18
 
18
- Arquivo build: `dist/v2/global.global.js`
19
+ Arquivo build recomendado: `dist/browser/pixel.global.js`
20
+
21
+ O artifact legado `dist/v2/global.global.js` continua gerado para consumidores que ainda apontam para `window.PixelV2` via caminho antigo.
19
22
 
20
23
  ## Subpaths avançados
21
24
 
@@ -23,7 +26,7 @@ Arquivo build: `dist/v2/global.global.js`
23
26
 
24
27
  | Subpath | Uso típico |
25
28
  |---------|------------|
26
- | `@beworke/pixel/config` | Tipos e helpers de config |
29
+ | `@beworke/pixel/config` | Tipos, `PixelSettings`, `resolvePixelConfig`, `DEFAULT_TRANSPORT_CONFIG` e demais helpers de config |
27
30
  | `@beworke/pixel/events` | Tipos `PixelEvent`, payloads de conversão |
28
31
  | `@beworke/pixel/runtime` | Runtime interno (uso avançado) |
29
32
  | `@beworke/pixel/services` | Serviços compartilhados |
@@ -40,8 +43,9 @@ Arquivo build: `dist/v2/global.global.js`
40
43
  ## Validar tarball
41
44
 
42
45
  ```bash
43
- npm pack --dry-run
44
- npm run validate:rc-package
46
+ pnpm pack:pixel
47
+ pnpm validate:pixel-package
48
+ pnpm smoke:pixel-package
45
49
  ```
46
50
 
47
- Arquivos publicados (`files`): `dist/`, `README.md`, `CHANGELOG.md`, `RELEASE_CANDIDATE.md`.
51
+ Arquivos publicados (`files`): `dist/`, `docs/public/`, `README.md`, `CHANGELOG.md`, `RELEASE_CANDIDATE.md`.
@@ -1,13 +1,28 @@
1
1
  # API — classe `Pixel`
2
2
 
3
- Superfície pública estável do RC `0.1.0-rc.5`. Métodos marcados `@internal` no código **não** fazem parte desta referência.
3
+ Superfície pública estável. A versão publicada está em `package.json`. Métodos marcados `@internal` no código **não** fazem parte desta referência.
4
4
 
5
- ## Construtor
5
+ ## Construtor e factory
6
6
 
7
7
  ```typescript
8
- import { Pixel, type PixelConfig } from '@beworke/pixel';
8
+ import { Pixel, createPixel, type PixelConfig, type PixelSettings } from '@beworke/pixel';
9
9
 
10
- const pixel = new Pixel(config);
10
+ const manual = new Pixel({ identity: { pixelId: 'pix_YOUR_ID' } });
11
+ await manual.init();
12
+
13
+ const pixel = await createPixel({ identity: { pixelId: 'pix_YOUR_ID' } });
14
+ ```
15
+
16
+ `createPixel` e o construtor aceitam `PixelSettings` (parcial). Um `PixelConfig` completo continua válido. O merge acontece uma única vez no construtor de `Pixel`.
17
+
18
+ `createPixel` cria uma instância independente, chama `init()` e só resolve depois. Se `init()` falhar, tenta `destroy()` e relança o erro original.
19
+
20
+ ## Bootstrap (`@beworke/pixel/browser`)
21
+
22
+ ```typescript
23
+ import { bootstrapPixel } from '@beworke/pixel/browser';
24
+
25
+ const pixel = await bootstrapPixel(config, { waitForConsent, force });
11
26
  ```
12
27
 
13
28
  ## Ciclo de vida
@@ -47,10 +62,16 @@ Tipos de dados: importe de `@beworke/pixel/events` se necessário.
47
62
 
48
63
  | Export | Uso |
49
64
  |--------|-----|
50
- | `DEFAULT_PIXEL_CONFIG` | Defaults auditados — base para merge |
51
- | `PixelConfig` | Tipo da configuração |
65
+ | `Pixel` | Classe pública |
66
+ | `createPixel` | Factory assíncrona (instâncias independentes) |
67
+ | `resolvePixelConfig` | Resolve `PixelSettings` → `PixelConfig` |
68
+ | `DEFAULT_PIXEL_CONFIG` | Defaults auditados — inspeção / avançado |
69
+ | `PixelSettings` | Tipo do input público (parcial) |
70
+ | `PixelConfig` | Tipo da configuração resolvida |
71
+ | `PixelConfigurationError` | Erro de `pixelId` / settings inválidos |
52
72
  | `PixelDebugSnapshot` | Tipo do snapshot |
53
73
  | `resolveStorageAdapterName` | Resolve nome do adapter de persistência |
74
+ | `SDK_VERSION` | Versão runtime alinhada a `package.json` |
54
75
 
55
76
  ## Não usar em produção / exemplos públicos
56
77
 
@@ -6,14 +6,14 @@ Configuração root-level (não dentro de `modules`).
6
6
 
7
7
  | Campo | Default | Descrição |
8
8
  |-------|---------|-----------|
9
- | `enabled` | `false` (via shared default) | Habilita enrichment commerce |
9
+ | `enabled` | `true` | Habilita enrichment commerce (catálogo vazio é no-op) |
10
10
  | `currency` | conforme `DEFAULT_COMMERCE_CONFIG` | Moeda padrão |
11
11
  | `catalog.products` | `[]` | Produtos da oferta (main, bump, upsell) |
12
12
  | `cart.mode` | `'custom'` | Carrinho gerenciado pelo app |
13
13
  | `cart.allowDynamicItems` | `true` | Itens dinâmicos no carrinho |
14
14
  | `cart.calculateValueFrom` | `'cart'` | Cálculo de `value` |
15
15
  | `mappings` | `{}` | Mapeamento de atributos/campos |
16
- | `enrichment` | defaults | Enriquece payloads de conversão |
16
+ | `enrichment` | pageView/viewContent/cart events on | Completa value/items a partir do catálogo e do carrinho |
17
17
 
18
18
  ## Quando usar
19
19
 
@@ -34,23 +34,20 @@ Referência resumida auditada contra `DEFAULT_PIXEL_CONFIG`.
34
34
 
35
35
  | Campo | Default | Descrição |
36
36
  |-------|---------|-----------|
37
- | `enabled` | `false` | Flag do módulo |
38
- | `manual.*` | `enabled: false` | Wrappers manuais internos |
39
- | `auto.enabled` | `false` | AutoTrack off |
40
- | `rules.enabled` | `false` | Regras por seletor/URL |
37
+ | `enabled` | `true` | Flag do módulo |
38
+ | `manual.*` | `enabled: true` | API manual pública |
39
+ | `auto.enabled` | `true` | AutoTrack on |
40
+ | `auto.detectors.*` | `data-track` | clique em todos; `view_content` também **hover** e **visível** |
41
+ | `auto.detectors.viewContent` | click + hover + visible | `[data-track="view_content"]` |
42
+ | `rules.enabled` | `false` | Regras extras por seletor/URL/texto |
41
43
 
42
- **Quando usar:** habilite `auto` + detectors para AutoTrack; ou use API `pixel.purchase()` etc. sem auto.
44
+ **Quando usar:** coloque `data-track="<evento>"` no HTML (e `data-product-id` / `data-email` / `data-query` quando o evento precisar). `view_content` dispara no clique, hover e visível; restrinja com `data-trigger="hover"` (ou `click` / `visible`, ou lista `hover,click`). Sem `data-trigger`, valem os 3. Para desligar: `auto.enabled: false`.
43
45
 
44
- ## `modules.transport`
46
+ ## Transport
45
47
 
46
- | Campo | Default | Descrição |
47
- |-------|---------|-----------|
48
- | `enabled` | `false` | **Deve ser `true` + `sender.mode: 'api'` para API real** |
49
- | `sender.mode` | `'mock'` | RC local usa mock até configurar API |
50
- | `batch.enabled` | `true` | Agrupa envios |
51
- | `retry`, `circuitBreaker`, `offline` | habilitados | Resiliência |
52
-
53
- **Quando usar:** produção/staging com `transport.apiEndpoint` e `sender.mode: 'api'`.
48
+ Transport não é módulo. Configure somente `config.transport`, usando os modos
49
+ `test`, `internal` ou `external`. Consulte a
50
+ [referência de Transport](./transport.md).
54
51
 
55
52
  ## `modules.integrations`
56
53
 
@@ -1,16 +1,41 @@
1
1
  # Configuração — visão geral
2
2
 
3
- `PixelConfig` é o objeto passado ao construtor `new Pixel(config)`.
3
+ O input público é `PixelSettings`. Somente `identity.pixelId` é obrigatório.
4
+ O construtor de `Pixel` chama `resolvePixelConfig(settings)` e entrega um
5
+ `PixelConfig` completo ao Runtime.
4
6
 
5
- Use `DEFAULT_PIXEL_CONFIG` como base e sobrescreva apenas o necessário.
7
+ ```ts
8
+ import { createPixel, type PixelSettings } from '@beworke/pixel';
9
+
10
+ const settings = {
11
+ identity: { pixelId: 'pix_YOUR_ID' },
12
+ app: { debug: true },
13
+ } satisfies PixelSettings;
14
+
15
+ const pixel = await createPixel(settings);
16
+ ```
17
+
18
+ `DEFAULT_PIXEL_CONFIG` continua disponível para inspeção e casos avançados.
19
+ Não é necessário espalhá-lo numa integração comum.
20
+
21
+ ## Semântica do merge
22
+
23
+ | Caso | Comportamento |
24
+ |------|----------------|
25
+ | Objetos plain | mescla profunda |
26
+ | Arrays | substituem o default (não concatenam) |
27
+ | `transport.sender` | substitui a variante inteira (`test` / `internal` / `external`) |
28
+ | `undefined` | ausência — o default permanece |
29
+ | `false` / `0` / `''` | valores válidos, preservados |
30
+ | Records (`mappings`, etc.) | mescla por chave |
6
31
 
7
32
  ## Top-level
8
33
 
9
34
  | Seção | Descrição |
10
35
  |-------|-----------|
11
36
  | `app` | Ambiente, debug, source/target |
12
- | `identity` | `pixelId`, IDs de funil, visitor, user |
13
- | `transport` | API endpoint, batch, timeout, retry |
37
+ | `identity` | `pixelId` (obrigatório no input), IDs de funil |
38
+ | `transport` | Sender, batch, timeout, retry e flush |
14
39
  | `storage` | Prefixo, namespace, fila, persistência |
15
40
  | `attribution` | UTM, cookies, persistência de atribuição |
16
41
  | `commerce` | Catálogo, carrinho, enrichment |
@@ -22,34 +47,25 @@ Use `DEFAULT_PIXEL_CONFIG` como base e sobrescreva apenas o necessário.
22
47
  |-------|---------|------|
23
48
  | `app.environment` | `'production'` | Use `'development'` + `debug: true` localmente |
24
49
  | `app.debug` | `false` | |
25
- | `identity.pixelId` | `''` | **Obrigatório** em produção |
26
- | `transport.apiEndpoint` | `''` | **Obrigatório** para enviar eventos |
27
- | `transport.timeoutMs` | `10000` | |
50
+ | `identity.pixelId` | `''` | Obrigatório no input; o resolvedor valida e faz trim |
51
+ | `transport.enabled` | `true` | Envia para a API interna pública |
52
+ | `transport.sender.mode` | `'internal'` | Sem segredo no browser; `baseUrl` público |
53
+ | `transport.timeout.timeoutMs` | `10000` | |
28
54
  | `storage.prefix` | `'__gmk'` | |
29
55
  | `storage.namespace` | `'pixel'` | |
56
+ | `storage.persistence.visitor` | `'localStorage'` | |
57
+ | `storage.persistence.session` | `'sessionStorage'` | |
58
+ | `storage.persistence.attribution` | `'localStorage'` | |
30
59
  | `storage.queue.enabled` | `true` | |
31
60
  | `storage.queue.persistence` | `'memory'` | |
32
61
  | `commerce.cart.mode` | `'custom'` | |
33
- | `modules.core.enabled` | ver [modules](./modules.md) | Emite `PAGE_VIEW` |
62
+ | `modules.core.enabled` | `true` | Emite `PAGE_VIEW` |
34
63
  | `modules.behavior.enabled` | `false` | Trackers off por default |
35
- | `modules.conversion.enabled` | `false` | Manual API ainda funciona quando módulo registrado |
36
- | `modules.transport.enabled` | ver modules | |
64
+ | `modules.conversion.enabled` | `true` | Métodos manuais on; AutoTrack `data-track` on; rules off |
65
+ | `commerce.enabled` | `true` | Enrichment on; catálogo vazio não altera payloads |
37
66
  | `modules.privacy.enabled` | ver modules | Sem CMP completo no RC |
38
67
 
39
- ## Persistência recomendada (funis)
40
-
41
- ```typescript
42
- storage: {
43
- ...DEFAULT_PIXEL_CONFIG.storage,
44
- persistence: {
45
- visitor: 'localStorage',
46
- session: 'sessionStorage',
47
- attribution: 'localStorage',
48
- },
49
- },
50
- ```
51
-
52
- Sem `persistence.session`, a sessão usa `memory` e some em reload/destroy React.
68
+ `identity.pixelId` aceita no máximo 128 caracteres após trim, sem caracteres de controle. O prefixo `pix_` não é exigido.
53
69
 
54
70
  ## Identity para funis
55
71
 
@@ -58,9 +74,9 @@ Campos úteis em `identity`:
58
74
  - `pixelId` — ID do pixel na API
59
75
  - `funnelId`, `funnelStepId` — etapa do funil
60
76
  - `pageId`, `offerId`, `checkoutId`
61
- - `visitorId`, `userId` — opcionais se gerenciados pelo backend
62
77
 
63
78
  ## Próximo
64
79
 
65
80
  - [Módulos](./modules.md)
81
+ - [Transport](./transport.md)
66
82
  - [Commerce](./commerce.md)
@@ -0,0 +1,127 @@
1
+ # Transport
2
+
3
+ O Transport possui uma única configuração top-level: `config.transport`.
4
+
5
+ Use `DEFAULT_TRANSPORT_CONFIG` como base avançada. No input público, basta
6
+ omitir `transport` para usar o sender `internal` default, ou substituir a
7
+ variante inteira:
8
+
9
+ ```typescript
10
+ import { Pixel } from '@beworke/pixel';
11
+
12
+ const pixel = new Pixel({
13
+ identity: { pixelId: 'pix_test' },
14
+ transport: {
15
+ sender: {
16
+ mode: 'test',
17
+ capture: true,
18
+ response: 'success',
19
+ delayMs: 0,
20
+ },
21
+ },
22
+ });
23
+ ```
24
+
25
+ Playgrounds podem ajustar o sender após `init()`:
26
+
27
+ ```typescript
28
+ pixel.configureTransportTestSender({
29
+ capture: true,
30
+ response: 'success',
31
+ delayMs: 0,
32
+ });
33
+ ```
34
+
35
+ `configureTransportTestSender()` é uma API interna para playground e
36
+ desenvolvimento; não a use como contrato de produção.
37
+
38
+ ## Internal sender com endpoint padrão
39
+
40
+ O modo `internal` envia para os endpoints públicos oficiais do Pixel. Sem
41
+ `baseUrl`, o SDK usa `DEFAULT_INTERNAL_TRANSPORT_BASE_URL`.
42
+
43
+ ```typescript
44
+ const pixel = new Pixel({
45
+ identity: { pixelId: 'pix_xxx' },
46
+ transport: {
47
+ sender: { mode: 'internal' },
48
+ },
49
+ });
50
+ ```
51
+
52
+ Os caminhos resolvidos são:
53
+
54
+ ```text
55
+ POST {baseUrl}/pixels/public/event
56
+ POST {baseUrl}/pixels/public/event/batch
57
+ ```
58
+
59
+ ## Internal sender com `baseUrl`
60
+
61
+ Use um `baseUrl` aprovado para staging, proxy próprio ou outra implantação
62
+ compatível com os endpoints internos:
63
+
64
+ ```typescript
65
+ transport: {
66
+ ...DEFAULT_TRANSPORT_CONFIG,
67
+ enabled: true,
68
+ sender: {
69
+ mode: 'internal',
70
+ baseUrl: 'https://pixel-api.example.com',
71
+ },
72
+ },
73
+ ```
74
+
75
+ ## External sender
76
+
77
+ Use `external` quando os endpoints não seguem os caminhos internos:
78
+
79
+ ```typescript
80
+ transport: {
81
+ ...DEFAULT_TRANSPORT_CONFIG,
82
+ enabled: true,
83
+ sender: {
84
+ mode: 'external',
85
+ endpoints: {
86
+ event: 'https://events.example.com/v1/event',
87
+ batch: 'https://events.example.com/v1/batch',
88
+ },
89
+ batchFallback: 'single',
90
+ headers: {
91
+ 'X-Public-Client': 'checkout-web',
92
+ },
93
+ },
94
+ },
95
+ ```
96
+
97
+ > Os headers são públicos e visíveis no browser. Nunca coloque token privado,
98
+ > API key secreta, credencial backend ou dado equivalente em
99
+ > `sender.headers`. Segredos devem ficar atrás de um servidor ou proxy
100
+ > confiável.
101
+
102
+ Se `endpoints.batch` não for informado, `batchFallback: 'single'` envia cada
103
+ evento pelo endpoint individual; `'error'` rejeita o envio em lote.
104
+
105
+ ## Batch, timeout e flush
106
+
107
+ `batch.maxWaitMs` controla a espera do lote. O intervalo periódico pertence a
108
+ `transport.flush.flushIntervalMs`.
109
+
110
+ ```typescript
111
+ transport: {
112
+ ...DEFAULT_TRANSPORT_CONFIG,
113
+ enabled: true,
114
+ sender: { mode: 'test', capture: true },
115
+ batch: {
116
+ ...DEFAULT_TRANSPORT_CONFIG.batch,
117
+ enabled: true,
118
+ batchSize: 10,
119
+ maxWaitMs: 5_000,
120
+ },
121
+ flush: {
122
+ ...DEFAULT_TRANSPORT_CONFIG.flush,
123
+ enabled: true,
124
+ flushIntervalMs: 2_000,
125
+ },
126
+ },
127
+ ```
@@ -2,7 +2,9 @@
2
2
 
3
3
  Fonte: union `PixelEvent` (`src/events/types.ts`) — **24 tipos** no RC.
4
4
 
5
- Todos os eventos listados abaixo passam pelo pipeline de transport quando `modules.transport.enabled` e `transport.apiEndpoint` estão configurados.
5
+ Todos os eventos listados abaixo passam pelo pipeline quando
6
+ `transport.enabled` está ativo. Os modos `internal` e `external` enviam pela
7
+ rede; `test` captura eventos sem requisição.
6
8
 
7
9
  > `ApiEventType` (HTTP) inclui tipos legados/históricos que **não** fazem parte de `PixelEvent`. Use esta tabela como catálogo público.
8
10
 
@@ -13,19 +13,13 @@ Pacote **público** — **não precisa de token** nem login npm para instalar:
13
13
  npm install @beworke/pixel@rc
14
14
  ```
15
15
 
16
- Versão fixa:
17
-
18
- ```bash
19
- npm install @beworke/pixel@0.1.0-rc.6
20
- ```
21
-
22
16
  Confirme a versão instalada:
23
17
 
24
18
  ```bash
25
19
  node -e "console.log(require('@beworke/pixel/package.json').version)"
26
20
  ```
27
21
 
28
- > Evite `npm install @beworke/pixel` sem tag até a tag `latest` apontar para a RC atual. Use `@rc` ou `@0.1.0-rc.6`.
22
+ > Evite `npm install @beworke/pixel` sem tag até a tag `latest` apontar para a RC atual. Use `@rc`.
29
23
 
30
24
  ## Onde ler a documentação
31
25
 
@@ -39,9 +33,12 @@ O site **npmjs.com não abre** arquivos `.md` individuais (ex.: `npmjs.com/packa
39
33
  ## Tarball local (opcional)
40
34
 
41
35
  ```bash
42
- npm install ./beworke-pixel-0.1.0-rc.6.tgz
36
+ pnpm pack:pixel
37
+ npm install ./artifacts/beworke-pixel-<versão>.tgz
43
38
  ```
44
39
 
40
+ A versão exata está em `package.json` / `artifacts/latest-package.json`.
41
+
45
42
  ## Validar instalação limpa
46
43
 
47
44
  Na raiz do monorepo:
@@ -49,6 +46,7 @@ Na raiz do monorepo:
49
46
  ```bash
50
47
  pnpm pack:pixel
51
48
  pnpm validate:pixel-package
49
+ pnpm smoke:pixel-package
52
50
  ```
53
51
 
54
52
  O tarball fica em `artifacts/` (não use `pnpm --filter @beworke/pixel pack` como fluxo principal).
@@ -56,7 +54,8 @@ O tarball fica em `artifacts/` (não use `pnpm --filter @beworke/pixel pack` com
56
54
  ## Imports recomendados
57
55
 
58
56
  ```typescript
59
- import { Pixel, DEFAULT_PIXEL_CONFIG, type PixelConfig } from '@beworke/pixel';
57
+ import { Pixel, createPixel, DEFAULT_PIXEL_CONFIG, type PixelConfig } from '@beworke/pixel';
58
+ import { bootstrapPixel } from '@beworke/pixel/browser';
60
59
  ```
61
60
 
62
61
  Subpaths adicionais: [Package exports](../api/exports.md).
@@ -64,9 +63,12 @@ Subpaths adicionais: [Package exports](../api/exports.md).
64
63
  ## CDN / script tag
65
64
 
66
65
  ```html
67
- <script src="https://unpkg.com/@beworke/pixel@rc/dist/v2/global.global.js"></script>
68
- <script>
69
- const { Pixel, DEFAULT_PIXEL_CONFIG } = window.PixelV2;
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
+ });
70
72
  </script>
71
73
  ```
72
74
 
@@ -1,49 +1,110 @@
1
1
  # Quick start
2
2
 
3
- ## 1. Config mínima
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`.
4
6
 
5
- ```typescript
6
- import { Pixel, DEFAULT_PIXEL_CONFIG } from '@beworke/pixel';
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.
7
12
 
8
- const pixel = new Pixel({
9
- ...DEFAULT_PIXEL_CONFIG,
10
- identity: {
11
- pixelId: 'pix_YOUR_ID',
12
- },
13
- transport: {
14
- ...DEFAULT_PIXEL_CONFIG.transport,
15
- apiEndpoint: 'https://your-pixel-api.example.com',
16
- },
17
- storage: {
18
- ...DEFAULT_PIXEL_CONFIG.storage,
19
- persistence: {
20
- visitor: 'localStorage',
21
- session: 'sessionStorage',
22
- attribution: 'localStorage',
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',
23
26
  },
24
- },
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' },
25
52
  });
26
53
  ```
27
54
 
28
- ## 2. Inicializar
55
+ A classe pública continua válida:
29
56
 
30
57
  ```typescript
58
+ import { Pixel } from '@beworke/pixel';
59
+
60
+ const pixel = new Pixel({
61
+ identity: { pixelId: 'pix_YOUR_ID' },
62
+ });
31
63
  await pixel.init();
32
64
  ```
33
65
 
34
- `init()` é assíncrono. Aguarde antes de disparar conversões manuais se depender de sessão/visitor prontos.
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
35
86
 
36
- ## 3. Eventos automáticos
87
+ Após `Pixel(settings)` / `createPixel` / `bootstrapPixel`:
37
88
 
38
- Com `modules.core.enabled` e `modules.behavior.enabled` (defaults), após `init()`:
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
39
96
 
40
- - `PAGE_VIEW` (core)
41
- - Sinais de behavior (scroll, cliques, heartbeat, etc.) conforme config
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
+ ```
42
103
 
43
- ## 4. Conversão manual
104
+ ## 5. Conversão manual
44
105
 
45
106
  ```typescript
46
- await pixel.purchase({
107
+ pixel.purchase({
47
108
  transactionId: 'order_123',
48
109
  value: 197,
49
110
  currency: 'BRL',
@@ -52,15 +113,15 @@ await pixel.purchase({
52
113
 
53
114
  Outros métodos: `lead`, `addToCart`, `removeFromCart`, `initiateCheckout`, `addPaymentInfo`, `viewContent`, `search`.
54
115
 
55
- ## 5. Encerrar (SPA / navegação)
116
+ ## 6. Encerrar (SPA / navegação)
56
117
 
57
118
  ```typescript
58
119
  await pixel.destroy();
59
120
  ```
60
121
 
61
- Em React/Next, chame `destroy()` no cleanup do `useEffect`.
122
+ Com `bootstrapPixel` / `window.Pixel`, prefira `destroyBootstrappedPixel()` / `Pixel.destroy()`. Em React, o `PixelProvider` é dono do lifecycle.
62
123
 
63
- ## 6. Debug (somente desenvolvimento)
124
+ ## 7. Debug (somente desenvolvimento)
64
125
 
65
126
  ```typescript
66
127
  if (pixel.isInitialized()) {
@@ -70,8 +131,12 @@ if (pixel.isInitialized()) {
70
131
 
71
132
  `getDebugSnapshot()` é público; não use `getDebugServices()` (interno).
72
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
+
73
136
  ## Próximos passos
74
137
 
75
138
  - [Configuração](../configuration/overview.md)
139
+ - [Transport](../configuration/transport.md)
76
140
  - [Catálogo de eventos](../events/catalog.md)
77
141
  - [Funil checkout](../guides/funnel-checkout.md)
142
+ - [React / Next.js](./react-nextjs.md)