@repobit/dex-data-layer 0.2.1 → 1.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/CHANGELOG.md +9 -0
- package/README.md +176 -5
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
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.1.0](https://github.com/bitdefender/dex-core/compare/@repobit/dex-data-layer@0.2.1...@repobit/dex-data-layer@1.1.0) (2025-04-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **DEX-22225:** added documentation ([12d2a0a](https://github.com/bitdefender/dex-core/commit/12d2a0aa1a5abad6119e93b897f729a1605cfbea))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
## [0.2.1](https://github.com/bitdefender/dex-core/compare/@repobit/dex-data-layer@0.2.0...@repobit/dex-data-layer@0.2.1) (2025-03-26)
|
|
7
16
|
|
|
8
17
|
|
package/README.md
CHANGED
|
@@ -1,11 +1,182 @@
|
|
|
1
|
-
# `@
|
|
1
|
+
# `@repobit/dex-data-layer`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# BD Adobe Data Layer Utilities
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
BD Adobe Data Layer Utilities is an npm package that provides a robust and flexible toolkit for managing and pushing events to Adobe’s Data Layer. It offers a collection of event classes (such as button clicks, form submissions, page load events, product events, etc.) along with a centralized service to handle event merging and dispatching to the global Adobe data layer. This ensures that events are recorded consistently for analytics and tracking.
|
|
6
6
|
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
This package standardizes the way web applications interact with Adobe’s Data Layer by:
|
|
12
|
+
|
|
13
|
+
- Defining a set of event classes that encapsulate common interactions (e.g., page events, product events, user actions).
|
|
14
|
+
- Providing a central service (`AdobeDataLayerService`) that manages the merging and pushing of these events into the global data layer (`window.adobeDataLayer`).
|
|
15
|
+
- Implementing a custom merge strategy for product-related events to prevent duplication and ensure data consistency.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Key Features
|
|
20
|
+
|
|
21
|
+
- **Event Abstraction:**
|
|
22
|
+
A comprehensive set of event classes, each with well-defined constructors and return types, to capture various user interactions and system events.
|
|
23
|
+
|
|
24
|
+
- **Centralized Data Layer Management:**
|
|
25
|
+
The `AdobeDataLayerService` class centralizes event management by merging events (especially product events) before dispatching them to the global data layer.
|
|
26
|
+
|
|
27
|
+
- **Custom Merge Strategy:**
|
|
28
|
+
Uses a tailored merge function to consolidate multiple `ProductLoadedEvent` entries, ensuring that only unique product details are retained.
|
|
29
|
+
|
|
30
|
+
- **Seamless Global Integration:**
|
|
31
|
+
Automatically integrates with the global `window.adobeDataLayer` array, making the pushed events readily available for Adobe Tag Management and analytics tools.
|
|
32
|
+
|
|
33
|
+
- **Extensive Use Cases:**
|
|
34
|
+
Comprehensive unit tests demonstrate real-world scenarios, including page load tracking, user detection, button clicks, and purchase events.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
This package relies on external dependencies:
|
|
41
|
+
- @repobit/dex-utils
|
|
42
|
+
- @repobit/dex-store
|
|
43
|
+
|
|
44
|
+
Install the package via npm or yarn:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install @repobit/dex-data-layer
|
|
48
|
+
```
|
|
49
|
+
# Classes and Their Constructors / Return Types
|
|
50
|
+
|
|
51
|
+
## AdobeDataLayerService
|
|
52
|
+
### Static class (not instantiated)
|
|
53
|
+
|
|
54
|
+
### Key Methods:
|
|
55
|
+
|
|
56
|
+
- ## push(event: DataLayerEvent): void
|
|
57
|
+
- ### Input: An instance of a DataLayerEvent (e.g., ButtonClickEvent, CdpEvent, etc.).
|
|
58
|
+
- ### Behavior:
|
|
59
|
+
- For `ProductLoadedEvent`, the event is merged into a local data structure (using the `deepmerge` library with a custom array merge function) keyed by the event name (e.g., `product loaded`). This allows multiple product events to be consolidated, reducing redundancy.
|
|
60
|
+
- For all other situations, the event is directly pushed to the global `window.adobeDataLayer`, making it immediately available for consumption by Adobe’s tag management tools.
|
|
61
|
+
- ## pushEventsToDataLayer(): void
|
|
62
|
+
- ### Behavior:
|
|
63
|
+
- Iterates through the locally stored events (like merged product events) and pushes them into the global data layer.
|
|
64
|
+
|
|
65
|
+
### Use case:
|
|
66
|
+
When a user action or system event occurs (for example, a button click or product load), create the corresponding event instance and call AdobeDataLayerService.push(event). For product events, later call AdobeDataLayerService.pushEventsToDataLayer() to flush the merged data.
|
|
67
|
+
|
|
68
|
+
## ButtonClickEvent
|
|
69
|
+
### Constructor: constructor(clickEvent: 'trial downloaded' | 'product downloaded' | string, productId: string)
|
|
70
|
+
### Return Type:
|
|
71
|
+
Returns an instance of `ButtonClickEvent` with:
|
|
72
|
+
- `event`: A string indicating the type of button click event.
|
|
73
|
+
- `product`: An object containing product details. For example, if the event is 'trial downloaded', the product object will have a trial key with an array of product IDs.
|
|
74
|
+
|
|
75
|
+
## CdpEvent
|
|
76
|
+
### Constructor: constructor(cdpData: CdpEventParameters)
|
|
77
|
+
### Return Type:
|
|
78
|
+
Returns an instance of `CdpEvent` with:
|
|
79
|
+
- `event`: Constant string `cdp data`.
|
|
80
|
+
- `parameters`: An object containing CDP parameters
|
|
81
|
+
|
|
82
|
+
## FormEvent
|
|
83
|
+
### Constructor: constructor(event: string, userObject: FormEventUserObject)
|
|
84
|
+
### Return Type:
|
|
85
|
+
Returns an instance of `FormEvent` with:
|
|
86
|
+
- `event`: A string representing the form event (e.g., `form completed`).
|
|
87
|
+
- `user`: An object containing form-specific data (such as form ID and form name).
|
|
88
|
+
|
|
89
|
+
## OneClickPurchaseEvent
|
|
90
|
+
### Constructor: constructor(event: string, cart: OneClickPurchaseEventCartObject, transaction: OneClickPurchaseEventTransactionObject)
|
|
91
|
+
### Return Type:
|
|
92
|
+
Returns an instance of `OneClickPurchaseEvent` with:
|
|
93
|
+
- `event`: A string representing the purchase event (e.g., `purchase`).
|
|
94
|
+
- `cart`: An object detailing the cart (if provided).
|
|
95
|
+
- `transaction`: An object detailing the transaction (if provided).
|
|
96
|
+
|
|
97
|
+
## PageErrorEvent
|
|
98
|
+
### Constructor: constructor()
|
|
99
|
+
### Return Type:
|
|
100
|
+
Returns an instance of `PageErrorEvent` with:
|
|
101
|
+
- `event`: Constant string `page error`.
|
|
102
|
+
|
|
103
|
+
## PageLoadStartedEvent
|
|
104
|
+
### Constructor: constructor(page: Page, pageData: PageLoadStartedDataObject)
|
|
105
|
+
### Return Type:
|
|
106
|
+
Returns an instance of `PageLoadStartedEvent` with:
|
|
107
|
+
- `event`: Constant string `page load started`.
|
|
108
|
+
- `pageInstanceID`: A value derived from the page’s environment (e.g., 'dev', 'stage', or 'prod').
|
|
109
|
+
- `page`: A complex object that contains detailed page information (sections, query parameters, server details, etc.) constructed from the provided Page instance and pageData. This object is easily constructed using the `Page class` from the `@repobit/dex-utils` package.
|
|
110
|
+
|
|
111
|
+
## PageLoadedEvent
|
|
112
|
+
### Constructor: constructor()
|
|
113
|
+
### Return Type:
|
|
114
|
+
Returns an instance of `PageLoadedEvent` with:
|
|
115
|
+
- `event`: Constant string `page loaded`.
|
|
116
|
+
|
|
117
|
+
## ProductLoadedEvent
|
|
118
|
+
### Constructor: constructor(option: ProductOption | { ID: string }, type: 'all' | 'info' | 'comparison' | string)
|
|
119
|
+
### Return Type:
|
|
120
|
+
Returns an instance of `ProductLoadedEvent` with:
|
|
121
|
+
- `event`: Constant string `product loaded`.
|
|
122
|
+
- `product`: An object where keys are the product type (e.g., all, info) and the values are arrays of product details (either raw product IDs or detailed option information).
|
|
123
|
+
|
|
124
|
+
## PromotionIdEvent
|
|
125
|
+
### Constructor: constructor(pageObject: PromotionIdEventPageObject)
|
|
126
|
+
### Return Type:
|
|
127
|
+
Returns an instance of `PromotionIdEvent` with:
|
|
128
|
+
- `event`: Constant string `promotion id event`.
|
|
129
|
+
- `page`: An object containing page attributes related to the promotion ID.
|
|
130
|
+
|
|
131
|
+
## UserDetectedEvent
|
|
132
|
+
### Constructor: constructor(page: Page, userData: UserDataObject)
|
|
133
|
+
### Return Type:
|
|
134
|
+
Returns an instance of `UserDetectedEvent` with:
|
|
135
|
+
- `event`: Constant string `user detected`.
|
|
136
|
+
- `user`: An object that includes user detection details (e.g., login status, unique identifiers).
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
# Usage Examples
|
|
141
|
+
|
|
142
|
+
## Page Load Started Event:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const testPage = new Page('en-us', 'consumer', 'dev');
|
|
146
|
+
AdobeDataLayerService.push(new PageLoadStartedEvent(testPage, {
|
|
147
|
+
name: 'en-us:consumer:solutions',
|
|
148
|
+
geoRegion: 'en-us'
|
|
149
|
+
}));
|
|
150
|
+
const insertedEvent = window.adobeDataLayer[0] as PageLoadStartedEvent;
|
|
151
|
+
console.log(insertedEvent.event); // "page load started"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## User Detected Event:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
AdobeDataLayerService.push(new UserDetectedEvent(testPage, {
|
|
158
|
+
ID: '9999',
|
|
159
|
+
productFinding: 'consumer-page'
|
|
160
|
+
}));
|
|
161
|
+
const insertedEvent = window.adobeDataLayer[0] as UserDetectedEvent;
|
|
162
|
+
console.log(insertedEvent.event); // "user detected"
|
|
7
163
|
```
|
|
8
|
-
import Target from '@bitdefender/dex-target';
|
|
9
164
|
|
|
10
|
-
|
|
165
|
+
## Button Click Event:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
AdobeDataLayerService.push(new ButtonClickEvent('trial downloaded', '9999'));
|
|
169
|
+
const insertedEvent = window.adobeDataLayer[0] as ButtonClickEvent;
|
|
170
|
+
console.log(insertedEvent.event); // "trial downloaded"
|
|
11
171
|
```
|
|
172
|
+
|
|
173
|
+
## Product Loaded Event:
|
|
174
|
+
The code below is just for example purposes. Product Option is generated by the `Store` and should only be used in the context of a `Store Resolver`.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
const option = new ProductOption({ /* product details */ });
|
|
178
|
+
AdobeDataLayerService.push(new ProductLoadedEvent(option, 'all'));
|
|
179
|
+
AdobeDataLayerService.pushEventsToDataLayer();
|
|
180
|
+
const insertedEvent = window.adobeDataLayer[0] as ProductLoadedEvent;
|
|
181
|
+
console.log(insertedEvent.event); // "product loaded"
|
|
182
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repobit/dex-data-layer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Client for Adobe Data Layer",
|
|
5
5
|
"author": "Constantin Ioan Mihai <iconstantin@bitdefender.com>",
|
|
6
6
|
"homepage": "https://github.com/bitdefender/dex-core#readme",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"volta": {
|
|
38
38
|
"node": "22.14.0"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "63cefae5c57ca4f1e886b623d1979bb369b3e777"
|
|
41
41
|
}
|