/** * GTM Integration. Will load the GTM script and write data on `window.dataLayer` * array. * * @example Adding GTM integration to analytics * ``` * * import analytics, \{ integrations \} from '\@farfetch/blackout-react/analytics'; * * analytics.addIntegration('GTM', integrations.GTM, \{ * containerId: '\' * \}); * * ``` */ import { type ConsentData, type EventContext, type EventData, integrations, type LoadIntegrationEventData, type SetUserEventData, type StrippedDownAnalytics, type TrackTypesValues } from '@farfetch/blackout-analytics'; import { GoogleConsentMode } from '../shared/index.js'; import type { EventMappers, GTMEventData, GTMIntegrationOptions } from './types/index.js'; import type { Schemas } from '../GA/index.js'; /** * GTM Integration. */ declare class GTM extends integrations.Integration { protected googleConsentMode: GoogleConsentMode; protected consentKey?: string; protected contextKey?: string; protected setUserKey?: string; protected context?: EventContext; protected eventsMapper: EventMappers; protected eventSchemas: Schemas; /** * Creates an instance of GTM. It will store the events mapper and the options * passed. * * @param options - Config for the GTM container. * @param loadData - Analytics's load event data. * @param analytics - Analytics instance stripped down with only helpers. */ constructor(options: GTMIntegrationOptions, loadData: LoadIntegrationEventData, analytics: StrippedDownAnalytics); /** * Method to check if the integration is ready to be loaded. This integration * should always load. Then, in the container, each tag should be configured with * the proper trigger according its category: Preferences, statistics or marketing. * * @returns If the integration is ready to be loaded. */ static shouldLoad(): boolean; /** * Startup the GTM script and write some properties on the dataLayer. There's no * need to wait for the script to load as GTM will pick up any data already written * on the dataLayer once it starts running. * * @param options - Integration options. * @param loadData - Analytics's load event data. */ initialize(options: GTMIntegrationOptions, loadData: LoadIntegrationEventData): void; /** * Loads the GTM script with the container ID passed via the integration's options. * * @param options - Integration options. * * @returns This allows chaining of class methods. */ runGTMScript(options: GTMIntegrationOptions): this; /** * Sets the consent object. This method is called by analytics whenever the consent * changes, so there's no need to validate if it has changed or not. * * @param consent - Object to be written on the dataLayer. * * @returns This allows chaining of class methods. */ setConsent(this: this, consent: ConsentData): this; /** * Workaround to handle when the context changes. Only write when it does change, * to avoid writing it on every event. * * @param context - The context passed in every event. * * @returns This allows chaining of class methods. */ setContext(context: EventContext): this; /** * Handles whenever the user changes. Will try to execute a custom "onSetUser" if * passed via the integration's options. * * @param data - OnSetUser event data. * * @returns This allows chaining of class methods. */ onSetUser(data: SetUserEventData | LoadIntegrationEventData): this; /** * Validates the event against a schema. If no schema is defined for the event, * assume the event is valid. * * @param data - Event data provided by analytics. * * @returns If the event passed schema validation or not. */ isEventDataValid(data: EventData): boolean; /** * Track a page or event and push it to the dataLayer. * * @param data - Analytics data. * * @returns This allows chaining of class methods. */ track(data: EventData): this; /** * Writes data on the `dataLayer` Array. * * @param data - Data to be written on the dataLayer. * * @returns This allows chaining of class methods. */ write(data: GTMEventData): this; } export default GTM;