@walkeros/web-source-datalayer
Version:
DataLayer source for walkerOS
290 lines (286 loc) • 6.2 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/examples/index.ts
var examples_exports = {};
__export(examples_exports, {
Events: () => events_exports,
Mapping: () => mapping_exports,
consentOnlyMapping: () => consentOnlyMapping,
consentUpdateEvent: () => consentUpdate,
dataLayerExamples: () => config2
});
module.exports = __toCommonJS(examples_exports);
// 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
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Events,
Mapping,
consentOnlyMapping,
consentUpdateEvent,
dataLayerExamples
});