/** * Google Analytics Integration. Will load the google analytics script and apply * the enhanced ecommerce plugin. * * @example Adding GA integration to analytics * ``` * * import analytics, \{ integrations \} from '\@farfetch/blackout-react/analytics'; * * analytics.addIntegration('GA', integrations.GA, \{ * createFields: \{ * trackingId: '\' * \} * \}); * * ``` */ import { type EventData, integrations, type LoadIntegrationEventData, type PageviewEventData, type SetUserEventData, type StrippedDownAnalytics, type TrackEventData, type TrackTypesValues, utils } from '@farfetch/blackout-analytics'; import type { EventScopeCommandsHandlers, GACommandList, GAIntegrationOptions, ProductMappings, ScopeCommands, ValidateCommandResult } from './types/index.js'; /** * Google Analytics Integration. */ declare class GA extends integrations.Integration { private initializePromiseResolve?; private initializePromise; private scopeCommands?; private schemaEventsMap; private productMappings; private onPreProcessCommands; private nonInteractionEvents; /** * Creates an instance of Google Analytics integration. Setup google analytics and * initializes event commands map that will be used to obtain the command list * associated with an event. * * @param options - User configured options. * @param loadData - Analytics's load event data. * @param strippedDownAnalytics - Analytics stripped down instance. */ constructor(options: GAIntegrationOptions, loadData: LoadIntegrationEventData, strippedDownAnalytics: StrippedDownAnalytics); static [utils.CONSENT_CATEGORIES_PROPERTY]: utils.DefaultConsentKeys; /** * Send page hits to GA. * * @param data - Event data provided by analytics. */ trackPage(data: PageviewEventData): Promise; /** * Send event hits to GA if the input event data passes schema validation. * * @param data - Event data provided by analytics. * * @returns Promise that will resolve when the method finishes. */ track(data: EventData): Promise; /** * Tracks an event. Send event hits to GA if the input event data passes schema * validation. * * @param data - Event data provided by analytics. */ trackEvent(data: TrackEventData): Promise; /** * Execute user scope commands builder if there is any specified. The command list * returned by the builder will be sent to GA instance. * * @param data - Event data provided by analytics. */ onSetUser(data: SetUserEventData | LoadIntegrationEventData): Promise; /** * 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; /** * Send event data to GA by compiling the data to a command list that will feed the * ga function. * * @param data - Event data provided by analytics. */ sendEvent(data: TrackEventData): void; /** * Feeds the ga instance with the command list passed in. * * @param gaCommandList - List of commands to be executed by ga instance. * @param data - Event data provided by analytics. */ processCommandList(gaCommandList: GACommandList | undefined, data: EventData | LoadIntegrationEventData | SetUserEventData): void; /** * Process the command list to check if there is an event that should receive the * command `nonInteraction`. If so, append the command to the list. * * @param gaCommandList - List of commands to be executed by ga instance. */ processInteractionEvents(gaCommandList: GACommandList): void; /** * Return a GA command list for the event. * * @param data - Event data provided by analytics. * @param scopeCommands - Commands by scope configuration. * @param productMappings - User-configured product property mappings. * * @returns The GA command list for the event. It will return empty if there is an error or no command * builders exist for the event. */ buildCommandListForEvent(data: TrackEventData, scopeCommands?: ScopeCommands, productMappings?: ProductMappings): GACommandList | undefined; /** * Returns extra commands to be sent to GA along with the main commands for a * pageview hit if there is an `extras` option configured for pageviews. * * @param data - Event data provided by analytics. * @param scopeCommands - Commands by scope configuration. * * @returns An array with the commands or null if there was an error executing the extra commands * builder. */ getExtraCommandsForPage(data: PageviewEventData, scopeCommands?: ScopeCommands): GACommandList | undefined; /** * Returns extra commands to be sent to GA along with the main commands for an * event hit if there is an `extras` option configured for the specified event. * * @param data - Event data provided by analytics. * @param scopeCommands - Commands by scope configuration. * * @returns An array with the commands or null if there was an error executing the extra commands * builder. */ getExtraCommandsForEvent(data: TrackEventData, scopeCommands?: ScopeCommands): GACommandList | undefined; /** * Returns the main commands that correspond to the event analytics has passed in. * * @param data - Event data provided by analytics. * @param scopeCommands - Commands by scope configuration. * @param productMappings - User-configured product property mappings. * * @returns An array with the commands or null if there was an error executing the main commands * builder. */ getMainCommandsForEvent(data: TrackEventData, scopeCommands?: ScopeCommands, productMappings?: ProductMappings): GACommandList | undefined; /** * Returns the main command builder for an event hit. * * @param event - Event name. * @param scopeCommands - Commands by scope configuration. * * @returns Main command builder for the hit if there is one, undefined otherwise. */ getMainCommandBuilderForEvent(event: string, scopeCommands?: ScopeCommands): EventScopeCommandsHandlers['main']; /** * Returns the extra commands builder for an event hit. * * @param event - Event name. * @param scopeCommands - Commands by scope configuration. * * @returns Extra commands builder for the hit if there is one, undefined otherwise. */ getExtrasCommandBuilderForEvent(event: string, scopeCommands?: ScopeCommands): EventScopeCommandsHandlers['extras']; /** * Executes a command builder. * * @throws * If the command builder passed is not a function or the output is not of the * proper type. * * @param commandBuilder - The command builder to execute. * @param args - Arguments to be passed to the command builder. * * @returns Output of the command builder execution. */ executeCommandBuilder GACommandList) | undefined>(commandBuilder: T, ...args: T extends (...args: any[]) => GACommandList ? Parameters : undefined[]): GACommandList | undefined | never; /** * Validates if the provided command list is in the expected format and if the * product category hierarchy values does not exceed the maximum supported levels * in GA. * * @param commandList - The command list to validate. * * @returns An object with a boolean `isValid` with the result of the validation and a string * `errorMessage` with the validation error if available. */ validateCommandList(commandList: GACommandList): ValidateCommandResult; /** * Initializes member variables from options and initializes google analytics with * Enhanced Ecommerce plugin. * * @param options - Options passed for the GA integration. */ initialize(options: GAIntegrationOptions): void; /** * Method that will be called when the GA script loads. */ onloadFn: () => void; } export default GA;