@walkeros/web-source-datalayer
Version:
DataLayer source for walkerOS
302 lines (298 loc) • 5.85 kB
JavaScript
var __defProp = Object.defineProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// src/examples/env.ts
var env_exports = {};
__export(env_exports, {
push: () => push
});
var noop = () => {
};
var createMockElbFn = () => {
const fn = (() => Promise.resolve({
ok: true,
successful: [],
queued: [],
failed: []
}));
return fn;
};
var createMockWindow = () => ({
dataLayer: [],
addEventListener: noop,
removeEventListener: noop
});
var push = {
get push() {
return createMockElbFn();
},
get command() {
return createMockElbFn();
},
get elb() {
return createMockElbFn();
},
get window() {
return createMockWindow();
}
};
// src/examples/events.ts
var events_exports = {};
__export(events_exports, {
add_to_cart: () => add_to_cart,
config: () => config,
consentDefault: () => consentDefault,
consentUpdate: () => consentUpdate,
directDataLayerEvent: () => directDataLayerEvent,
purchase: () => purchase,
setCustom: () => setCustom,
view_item: () => view_item
});
function consentUpdate() {
return [
"consent",
"update",
{
ad_user_data: "granted",
ad_personalization: "granted",
ad_storage: "denied",
analytics_storage: "granted"
}
];
}
function consentDefault() {
return [
"consent",
"default",
{
ad_storage: "denied",
analytics_storage: "denied",
ad_user_data: "denied",
ad_personalization: "denied"
}
];
}
function purchase() {
return [
"event",
"purchase",
{
transaction_id: "T_12345",
value: 25.42,
currency: "EUR",
items: [
{
item_id: "SKU_12345",
item_name: "Product Name",
item_category: "Category",
quantity: 1,
price: 25.42
}
]
}
];
}
function add_to_cart() {
return [
"event",
"add_to_cart",
{
currency: "EUR",
value: 15.25,
items: [
{
item_id: "SKU_12345",
item_name: "Product Name",
item_variant: "red",
quantity: 1,
price: 15.25
}
]
}
];
}
function view_item() {
return [
"event",
"view_item",
{
currency: "EUR",
value: 15.25,
items: [
{
item_id: "SKU_12345",
item_name: "Product Name",
item_category: "Category",
price: 15.25
}
]
}
];
}
function config() {
return [
"config",
"G-XXXXXXXXXX",
{
page_title: "Custom Page Title",
page_location: "https://example.com/page",
send_page_view: false
}
];
}
function setCustom() {
return [
"set",
{
currency: "EUR",
country: "DE"
}
];
}
function directDataLayerEvent() {
return {
event: "custom_event",
custom_parameter: "custom_value",
user_id: "user123"
};
}
// src/examples/mapping.ts
var mapping_exports = {};
__export(mapping_exports, {
add_to_cart: () => add_to_cart2,
config: () => config2,
configGA4: () => configGA4,
consentOnlyMapping: () => consentOnlyMapping,
consentUpdate: () => consentUpdate2,
customEvent: () => customEvent,
purchase: () => purchase2,
view_item: () => view_item2
});
var consentUpdate2 = {
name: "walker consent",
settings: {
command: {
map: {
functional: { value: true },
// Static value - always true for functional
analytics: {
key: "analytics_storage",
fn: (value) => value === "granted"
},
marketing: {
key: "ad_storage",
fn: (value) => value === "granted"
}
}
}
}
};
var purchase2 = {
name: "order complete",
data: {
map: {
id: "transaction_id",
total: "value",
currency: "currency",
nested: {
loop: [
"items",
{
map: {
type: { value: "product" },
data: {
map: {
id: "item_id",
name: "item_name",
category: "item_category",
quantity: "quantity",
price: "price"
}
}
}
}
]
}
}
}
};
var add_to_cart2 = {
name: "product add",
data: {
map: {
id: "items.0.item_id",
name: "items.0.item_name",
price: "value",
currency: "currency",
color: "items.0.item_variant",
quantity: "items.0.quantity"
}
}
};
var view_item2 = {
name: "product view",
data: {
map: {
id: "items.0.item_id",
name: "items.0.item_name",
category: "items.0.item_category",
price: "items.0.price",
currency: "currency"
}
}
};
var configGA4 = {
name: "page view",
data: {
map: {
title: "page_title",
url: "page_location"
}
}
};
var customEvent = {
// Keep original event name with gtag prefix
data: {
map: {
// Map all properties as-is
user_id: "user_id",
custom_parameter: "custom_parameter"
}
}
};
var config2 = {
// Consent events
consent: {
update: consentUpdate2
},
// E-commerce events
purchase: purchase2,
add_to_cart: add_to_cart2,
view_item: view_item2,
// Config events
"config G-XXXXXXXXXX": configGA4,
// Custom events
custom_event: customEvent,
// Catch-all for unmapped events
"*": {
// Pass through with gtag prefix
data: {
// Copy all data as-is
}
}
};
var consentOnlyMapping = {
consent: {
update: consentUpdate2
}
};
export {
events_exports as Events,
mapping_exports as Mapping,
consentOnlyMapping,
consentUpdate as consentUpdateEvent,
config2 as dataLayerExamples,
env_exports as env
};