A multi-framework utility package for managing XP Data Layer events, with built-in support for React, Svelte, and Angular (Coming Soon).
Using Bun:
bun add unified-datalayer
Using npm:
npm install unified-datalayer
Using yarn:
yarn add unified-datalayer
Include the Adobe Data Layer script in your HTML:
For further instructions on this implementation visit adobe-client-data-layer
<script src="adobe-client-data-layer.min.js" async defer></script>
Then initialize the data layer in your application:
import { DataLayer } from 'unified-datalayer';
// Initialize with required site information
DataLayer.init({
siteInfo: {
name: "my-site",
experience: "desktop",
currency: "USD",
division: "myCompany",
domain: window.location.host,
env: "prod",
version: "2.0.0"
}
});
// Coming Soon
// Coming Soon
// Coming Soon
import { DataLayer } from 'unified-datalayer';
// Define the DataLayer Class (Optional for easier reuse)
const dl = new DataLayer();
// Initialize
dl.init({
siteInfo: {
name: "my-site",
experience: "desktop",
currency: "USD",
division: "myCompany",
domain: window.location.host,
env: "prod",
version: "2.0.0"
}
});
// Track home page
dl.page.home();
// Track product view
dl.pdp.view({
id: '123',
name: 'Example Product',
price: 99.99
});
// Add event listeners
document.querySelector('#add-to-cart').addEventListener('click', () => {
dl.cart.add({
id: '123',
name: 'Example Product',
price: 99.99
});
});
DataLayer.home.view(customData?)
: Track home page viewDataLayer.plp.view(listName?, customData?)
: Track product listing viewDataLayer.pdp.view(productData, customData?)
: Track product detail viewDataLayer.cart.add(productData, quantity?, customData?)
: Track add to cartDataLayer.checkout.step1(option?, customData?)
: Track checkout stepDataLayer.account.loginStart(customData?)
: Track user loginDataLayer.custom(eventName, eventData?)
: Track custom event# Clone the repository
git clone https://github.com/JordanRobo/xp-datalayer-manager.git
cd xp-datalayer-manager
# Install dependencies
bun install
# Run tests
bun test
# Build the package
bun run build
MIT