@contentful/optimization-web 0.1.0-alpha

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +491 -0
  3. package/dist/AutoEntryViewTracking.d.ts +88 -0
  4. package/dist/AutoEntryViewTracking.d.ts.map +1 -0
  5. package/dist/Optimization.d.ts +146 -0
  6. package/dist/Optimization.d.ts.map +1 -0
  7. package/dist/analyzer.html +4 -0
  8. package/dist/builders/EventBuilder.d.ts +42 -0
  9. package/dist/builders/EventBuilder.d.ts.map +1 -0
  10. package/dist/builders/index.d.ts +2 -0
  11. package/dist/builders/index.d.ts.map +1 -0
  12. package/dist/contentful-optimization-web.umd.cjs +2 -0
  13. package/dist/contentful-optimization-web.umd.cjs.map +1 -0
  14. package/dist/global-constants.d.ts +37 -0
  15. package/dist/global-constants.d.ts.map +1 -0
  16. package/dist/handlers/beaconHandler.d.ts +24 -0
  17. package/dist/handlers/beaconHandler.d.ts.map +1 -0
  18. package/dist/handlers/createOnlineChangeListener.d.ts +34 -0
  19. package/dist/handlers/createOnlineChangeListener.d.ts.map +1 -0
  20. package/dist/handlers/createVisibilityChangeListener.d.ts +40 -0
  21. package/dist/handlers/createVisibilityChangeListener.d.ts.map +1 -0
  22. package/dist/handlers/index.d.ts +4 -0
  23. package/dist/handlers/index.d.ts.map +1 -0
  24. package/dist/index.cjs +2 -0
  25. package/dist/index.cjs.map +1 -0
  26. package/dist/index.d.ts +7 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +6244 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/observers/ElementExistenceObserver.d.ts +195 -0
  31. package/dist/observers/ElementExistenceObserver.d.ts.map +1 -0
  32. package/dist/observers/ElementView.d.ts +178 -0
  33. package/dist/observers/ElementView.d.ts.map +1 -0
  34. package/dist/observers/ElementViewObserver.d.ts +164 -0
  35. package/dist/observers/ElementViewObserver.d.ts.map +1 -0
  36. package/dist/observers/index.d.ts +6 -0
  37. package/dist/observers/index.d.ts.map +1 -0
  38. package/dist/storage/LocalStore.d.ts +111 -0
  39. package/dist/storage/LocalStore.d.ts.map +1 -0
  40. package/dist/storage/index.d.ts +3 -0
  41. package/dist/storage/index.d.ts.map +1 -0
  42. package/dist/test/helpers.d.ts +41 -0
  43. package/dist/test/helpers.d.ts.map +1 -0
  44. package/dist/visualizer.html +4687 -0
  45. package/package.json +28 -0
@@ -0,0 +1,146 @@
1
+ import { type App, CoreStateful, type CoreStatefulConfig } from '@contentful/optimization-core';
2
+ import { type ElementViewElementOptions, type ElementViewObserverOptions } from './observers';
3
+ declare global {
4
+ interface Window {
5
+ /** Global Optimization class constructor attached by the Web SDK. */
6
+ Optimization?: typeof Optimization;
7
+ /** Singleton instance created by the Web SDK initializer. */
8
+ optimization?: Optimization;
9
+ }
10
+ }
11
+ interface CookieAttributes {
12
+ domain?: string;
13
+ /**
14
+ * Determines the expiration date of the cookie as the number of days until the cookie expires.
15
+ */
16
+ expires?: number;
17
+ }
18
+ /**
19
+ * Configuration options for the Optimization Web SDK.
20
+ *
21
+ * @public
22
+ * @remarks
23
+ * Extends {@link CoreStatefulConfig} with Web-specific options such as the
24
+ * application descriptor and automatic entry view tracking.
25
+ */
26
+ export interface OptimizationWebConfig extends CoreStatefulConfig {
27
+ /**
28
+ * Application metadata used to identify the Web app in downstream events.
29
+ */
30
+ app?: App;
31
+ /**
32
+ * Whether the SDK should automatically track entry views based on DOM
33
+ * attributes and observers.
34
+ *
35
+ * @defaultValue `false`
36
+ */
37
+ autoTrackEntryViews?: boolean;
38
+ cookie?: CookieAttributes;
39
+ }
40
+ /**
41
+ * Stateful Web SDK built on top of {@link CoreStateful}.
42
+ *
43
+ * @public
44
+ * @remarks
45
+ * Provides browser-specific wiring:
46
+ * - automatic persistence of consent, profile, and personalizations,
47
+ * - cookie-based anonymous ID handling,
48
+ * - automatic entry view tracking via IntersectionObserver and MutationObserver,
49
+ * - online-change based flushing of events,
50
+ * - and visibility-change based flushing of events.
51
+ *
52
+ * A singleton instance is attached to `window.optimization` when constructed
53
+ * in a browser environment.
54
+ */
55
+ declare class Optimization extends CoreStateful {
56
+ private elementViewObserver?;
57
+ private elementExistenceObserver?;
58
+ private autoTrackEntryViews;
59
+ private readonly cookieAttributes?;
60
+ /**
61
+ * Create a new Optimization Web SDK instance.
62
+ *
63
+ * @param config - Web SDK configuration.
64
+ *
65
+ * @throws If an `Optimization` instance has already been initialized on
66
+ * `window.optimization`.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import Optimization from '@contentful/optimization-web'
71
+ *
72
+ * const optimization = new Optimization({
73
+ * clientId: 'abc-123',
74
+ * environment: 'main',
75
+ * autoTrackEntryViews: true,
76
+ * })
77
+ * ```
78
+ */
79
+ constructor(config: OptimizationWebConfig);
80
+ private setAnonymousId;
81
+ /**
82
+ * Enable automatic entry view tracking for elements with `data-ctfl-*`
83
+ * attributes and start observing the document.
84
+ *
85
+ * @param options - Optional per-element observer defaults for dwell time,
86
+ * retries, and backoff behavior.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * optimization.startAutoTrackingEntryViews({ dwellTimeMs: 1000 })
91
+ * ```
92
+ */
93
+ startAutoTrackingEntryViews(options?: ElementViewObserverOptions): void;
94
+ /**
95
+ * Disable automatic entry view tracking and disconnect underlying observers.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * optimization.stopAutoTrackingEntryViews()
100
+ * ```
101
+ */
102
+ stopAutoTrackingEntryViews(): void;
103
+ /**
104
+ * Begin tracking entry views for a specific element, using the Web SDK’s
105
+ * dwell-time and retry logic.
106
+ *
107
+ * @param element - Element to observe.
108
+ * @param options - Per-element observer options and callback data.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * const element = document.querySelector('#hero')!
113
+ * optimization.trackEntryViewForElement(element, {
114
+ * dwellTimeMs: 1500,
115
+ * data: { entryId: 'xyz' },
116
+ * })
117
+ * ```
118
+ */
119
+ trackEntryViewForElement(element: Element, options: ElementViewElementOptions): void;
120
+ /**
121
+ * Stop tracking entry views for a specific element.
122
+ *
123
+ * @param element - Element to stop observing.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * optimization.untrackEntryViewForElement(element)
128
+ * ```
129
+ */
130
+ untrackEntryViewForElement(element: Element): void;
131
+ /**
132
+ * Reset all Web SDK state:
133
+ * - stops auto-tracking entry views,
134
+ * - clears the anonymous ID cookie,
135
+ * - clears LocalStore caches,
136
+ * - and delegates to {@link CoreStateful.reset} for underlying state reset.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * optimization.reset()
141
+ * ```
142
+ */
143
+ reset(): void;
144
+ }
145
+ export default Optimization;
146
+ //# sourceMappingURL=Optimization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Optimization.d.ts","sourceRoot":"","sources":["../src/Optimization.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,GAAG,EACR,YAAY,EACZ,KAAK,kBAAkB,EAIxB,MAAM,+BAA+B,CAAA;AAetC,OAAO,EAEL,KAAK,yBAAyB,EAE9B,KAAK,0BAA0B,EAChC,MAAM,aAAa,CAAA;AAKpB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,qEAAqE;QACrE,YAAY,CAAC,EAAE,OAAO,YAAY,CAAA;QAClC,6DAA6D;QAC7D,YAAY,CAAC,EAAE,YAAY,CAAA;KAC5B;CACF;AAED,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAID;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D;;OAEG;IACH,GAAG,CAAC,EAAE,GAAG,CAAA;IAET;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAE7B,MAAM,CAAC,EAAE,gBAAgB,CAAA;CAC1B;AAsDD;;;;;;;;;;;;;;GAcG;AACH,cAA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