@walkeros/web-source-datalayer
Version:
DataLayer source for walkerOS
134 lines (125 loc) • 4.54 kB
text/typescript
import { WalkerOS, Source, Mapping, Collector } from '@walkeros/core';
declare global {
interface Window {
dataLayer?: DataLayer;
[key: string]: DataLayer | unknown;
}
}
interface DataLayerSourceConfig extends Source.Config {
type: 'dataLayer';
settings: Settings;
}
type DataLayer = Array<unknown>;
interface Settings extends Record<string, unknown> {
name?: string;
prefix?: string;
filter?: (event: unknown) => WalkerOS.PromiseOrValue<boolean>;
}
type DataLayerEvent = {
event: string;
[key: string]: unknown;
};
type MappedEvent = {
event?: WalkerOS.DeepPartialEvent & {
id: string;
};
command?: {
name: string;
data: unknown;
};
};
type index_DataLayer = DataLayer;
type index_DataLayerEvent = DataLayerEvent;
type index_DataLayerSourceConfig = DataLayerSourceConfig;
type index_MappedEvent = MappedEvent;
type index_Settings = Settings;
declare namespace index {
export type { index_DataLayer as DataLayer, index_DataLayerEvent as DataLayerEvent, index_DataLayerSourceConfig as DataLayerSourceConfig, index_MappedEvent as MappedEvent, index_Settings as Settings };
}
/**
* Sample gtag events that would be pushed to dataLayer
* These represent real-world gtag calls that the dataLayer source should transform to WalkerOS events
*/
/**
* Consent Mode Events - Primary use case
*/
declare function consentUpdate$1(): unknown[];
declare function consentDefault(): unknown[];
/**
* E-commerce Events
*/
declare function purchase$1(): unknown[];
declare function add_to_cart$1(): unknown[];
declare function view_item$1(): unknown[];
/**
* Config Events
*/
declare function config$1(): unknown[];
/**
* Set Events
*/
declare function setCustom(): unknown[];
/**
* Direct dataLayer object pushes (not gtag)
*/
declare function directDataLayerEvent(): Record<string, unknown>;
declare const events_consentDefault: typeof consentDefault;
declare const events_directDataLayerEvent: typeof directDataLayerEvent;
declare const events_setCustom: typeof setCustom;
declare namespace events {
export { add_to_cart$1 as add_to_cart, config$1 as config, events_consentDefault as consentDefault, consentUpdate$1 as consentUpdate, events_directDataLayerEvent as directDataLayerEvent, purchase$1 as purchase, events_setCustom as setCustom, view_item$1 as view_item };
}
/**
* Consent Mode Mapping - Primary use case
* Maps gtag consent events to walker consent commands
*/
declare const consentUpdate: Mapping.Rule;
/**
* E-commerce Event Mappings
* Transform GA4 ecommerce events to WalkerOS events
*/
declare const purchase: Mapping.Rule;
declare const add_to_cart: Mapping.Rule;
declare const view_item: Mapping.Rule;
/**
* Config Event Mapping
* Transform GA4 config events to WalkerOS page events
*/
declare const configGA4: Mapping.Rule;
/**
* Custom Event Mapping
* Handle direct dataLayer pushes
*/
declare const customEvent: Mapping.Rule;
/**
* Complete mapping configuration
* Following the same pattern as destination mappings
*/
declare const config: Mapping.Rules;
/**
* Minimal consent-only mapping for focused use cases
*/
declare const consentOnlyMapping: Mapping.Rules;
declare const mapping_add_to_cart: typeof add_to_cart;
declare const mapping_config: typeof config;
declare const mapping_configGA4: typeof configGA4;
declare const mapping_consentOnlyMapping: typeof consentOnlyMapping;
declare const mapping_consentUpdate: typeof consentUpdate;
declare const mapping_customEvent: typeof customEvent;
declare const mapping_purchase: typeof purchase;
declare const mapping_view_item: typeof view_item;
declare namespace mapping {
export { mapping_add_to_cart as add_to_cart, mapping_config as config, mapping_configGA4 as configGA4, mapping_consentOnlyMapping as consentOnlyMapping, mapping_consentUpdate as consentUpdate, mapping_customEvent as customEvent, mapping_purchase as purchase, mapping_view_item as view_item };
}
/**
* DataLayer source factory function
* Intercepts dataLayer.push calls and transforms them to WalkerOS events
*/
declare function sourceDataLayer(init?: Partial<Settings>): Source.Init<DataLayerSourceConfig> & {
init?: (collector: Collector.Instance, config: {
settings: Settings;
}) => void;
settings?: Settings;
type?: string;
};
export { events as Events, mapping as Mapping, index as SourceDataLayer, consentOnlyMapping, consentUpdate$1 as consentUpdateEvent, config as dataLayerExamples, sourceDataLayer as default, sourceDataLayer };