diff --git a/packages/pages-components/src/components/analytics/Analytics.ts b/packages/pages-components/src/components/analytics/Analytics.ts index 28d78038..3b3f47a8 100644 --- a/packages/pages-components/src/components/analytics/Analytics.ts +++ b/packages/pages-components/src/components/analytics/Analytics.ts @@ -145,8 +145,17 @@ export class Analytics implements AnalyticsMethods { return Promise.resolve(); } - const { action, scope, eventName, currency, amount, destinationUrl, customTags, customValues } = - props; + const { + action, + scope, + eventName, + currency, + amount, + destinationUrl, + customTags, + customValues, + entity, + } = props; let value; if (amount) { @@ -166,6 +175,8 @@ export class Analytics implements AnalyticsMethods { destinationUrl: destinationUrl || undefined, customTags, customValues, + // only overwrite the default entity value when explicitly provided to track + ...(entity !== undefined && { entity }), }); } diff --git a/packages/pages-components/src/components/analytics/interfaces.ts b/packages/pages-components/src/components/analytics/interfaces.ts index bd94da6f..e099bcb2 100644 --- a/packages/pages-components/src/components/analytics/interfaces.ts +++ b/packages/pages-components/src/components/analytics/interfaces.ts @@ -10,6 +10,12 @@ export type TrackProps = { currency?: string; customTags?: Record; customValues?: Record; + /** + * The Yext entity to which the event corresponds. If passed as a string, the value is + * the mutable, customer-settable entity ID for the entity associated with the event. + * If passed as a number, it is the immutable internal entity ID (UID) set by the system. + */ + entity?: string | number; }; /**