@repobit/dex-store-elements 1.2.5 → 1.2.6

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.2.6](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.2.5...@repobit/dex-store-elements@1.2.6) (2025-10-31)
7
+
8
+ **Note:** Version bump only for package @repobit/dex-store-elements
9
+
10
+
11
+
12
+
13
+
6
14
  ## [1.2.5](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.2.4...@repobit/dex-store-elements@1.2.5) (2025-10-28)
7
15
 
8
16
  **Note:** Version bump only for package @repobit/dex-store-elements
package/README.md CHANGED
@@ -35,6 +35,21 @@ Peer dependencies are resolved automatically by npm; no extra install command is
35
35
  provider: { name: 'vlaicu' }
36
36
  });
37
37
 
38
+ // Optional: analytics data layer callback
39
+ // Fires once per <bd-option> that sets `data-layer-event`
40
+ root.dataLayer = ({ option, event }) => {
41
+ // Example GTM-style push; adapt fields as needed
42
+ window.dataLayer?.push({
43
+ event,
44
+ productId : option.getProduct().getId(),
45
+ campaign : option.getProduct().getCampaign(),
46
+ variation : option.getVariation(), // e.g. "5-12"
47
+ devices : option.getDevices(),
48
+ subscription: option.getSubscription(),
49
+ price : option.getDiscountedPrice({ currency: false })
50
+ });
51
+ };
52
+
38
53
  // Optional: define derived values/functions for templates + hide DSL
39
54
  root.derived = async ({ option }) => ({
40
55
  mails: (p) => ((option?.getDevices?.() ?? 0) / p) * 100
@@ -47,7 +62,7 @@ Peer dependencies are resolved automatically by npm; no extra install command is
47
62
 
48
63
  <bd-root store-name="root">
49
64
  <bd-product store-name="product" product-id="com.bitdefender.tsmd.v2">
50
- <bd-option devices="5" subscription="12">
65
+ <bd-option devices="5" subscription="12" data-layer-event="info">
51
66
  <!-- Attribute renderers (see below) -->
52
67
  <div data-store-render data-store-devices></div>
53
68
  <div data-store-render data-store-subscription data-store-subscription-type="years"></div>
@@ -239,6 +254,58 @@ Notes
239
254
  - All price/discount values in the DSL are formatted strings (currency-aware). Do not perform numeric comparisons on them. Prefer truthiness checks (e.g., `!it.option.price.discounted`).
240
255
  - `it.ctx` is an alias of `it.state` for convenience.
241
256
 
257
+ ## Data Layer
258
+ - Provide a function on `<bd-root>`: `root.dataLayer = ({ option, event }) => { ... }`.
259
+ - Called once per `<bd-option>` instance that declares `data-layer-event` (on first successful load).
260
+ - Safe if attached after the option loads; it still fires once when available.
261
+ - Intended for analytics (e.g., pushing to `window.dataLayer`).
262
+ - Event name is set on each `<bd-option>` with `data-layer-event`.
263
+ - Canonical values: `all`, `info`, `comparison`. Any custom string is also accepted.
264
+ - Payload shape passed to your callback:
265
+ - `event`: string event name.
266
+ - `option`: `ProductOption` from `@repobit/dex-store` with getters like `getProduct()`, `getVariation()`, `getDevices()`, `getSubscription()`, `getBuyLink()`, `getDiscountedPrice()`.
267
+
268
+ Example:
269
+
270
+ ```html
271
+ <script type="module">
272
+ import { registerContextNodes, registerActionNodes } from '@repobit/dex-store-elements';
273
+ import { Store } from '@repobit/dex-store';
274
+
275
+ window.addEventListener('DOMContentLoaded', async () => {
276
+ registerContextNodes();
277
+ const root = document.querySelector('bd-root');
278
+ root.store = new Store({ locale: 'en-us', provider: { name: 'vlaicu' } });
279
+
280
+ root.dataLayer = ({ option, event }) => {
281
+ window.dataLayer = window.dataLayer || [];
282
+ window.dataLayer.push({
283
+ event,
284
+ productId: option.getProduct().getId(),
285
+ campaign : option.getProduct().getCampaign(),
286
+ variation: option.getVariation(),
287
+ devices : option.getDevices(),
288
+ subscription: option.getSubscription()
289
+ });
290
+ };
291
+
292
+ registerActionNodes(root);
293
+ });
294
+ </script>
295
+
296
+ <bd-root store-name="root">
297
+ <bd-product store-name="product" product-id="com.bitdefender.tsmd.v2">
298
+ <bd-option devices="5" subscription="12" data-layer-event="info">
299
+ <!-- your UI here -->
300
+ </bd-option>
301
+ </bd-product>
302
+ </bd-root>
303
+ ```
304
+
305
+ Behavior notes
306
+ - Fires only once per `<bd-option>` instance (first load). Subsequent changes via actions or deltas do not trigger the callback again.
307
+ - Set different `data-layer-event` values on different options if you need multiple distinct analytics events.
308
+
242
309
  ## Actions
243
310
  - Add `data-store-action` to elements to emit store events.
244
311
  - Set absolute values: `data-store-set-devices`, `data-store-set-subscription`, `data-store-set-id`, `data-store-set-campaign`
@@ -1,7 +1,7 @@
1
1
  import type { ProductOption } from '@repobit/dex-store';
2
2
  export type dataLayerPayload = {
3
3
  option: ProductOption;
4
- event: "product-loaded" | "main-product-loaded" | "product-comparison" | (string & {});
4
+ event: "all" | "info" | "comparison" | (string & {});
5
5
  };
6
6
  export type dataLayerContextType = ((payload: dataLayerPayload) => void) | undefined;
7
7
  export declare const dataLayerContext: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repobit/dex-store-elements",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "HTML elements layer for pricings",
5
5
  "author": "Buga Adrian Alexandru <abuga@bitdefender.com>",
6
6
  "homepage": "https://github.com/bitdefender/dex-core#readme",
@@ -62,5 +62,5 @@
62
62
  ]
63
63
  }
64
64
  },
65
- "gitHead": "9994983ec6b6d8140dbb2cfb2c11a6935943381e"
65
+ "gitHead": "45026ddb310bc191c78072fa27ab36ec1049fa0d"
66
66
  }