Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ export const ExoEventProperties = z.extend(UniversalEventProperties, {
/** Contentful entry identifiers rendered by the entity. */
entryIds: z.optional(z.array(z.string())),

/** Identifier of the optimization that selected the entity variant. */
optimizationId: z.string(),
/** Identifier of the optimization that selected the entity variant, when available. */
optimizationId: z.optional(z.string()),

/** Parameter values used to render the entity. */
parameters: z.optional(z.record(z.string(), z.json())),

/** Identifier of the containing experience, when the entity is nested. */
parentExperienceId: z.optional(z.string()),

/** Identifier of the selected entity variant. */
variantId: z.string(),
/** Identifier of the selected entity variant, when available. */
variantId: z.optional(z.string()),

/** Index of the selected variant when available. */
variantIndex: z.optional(z.number()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const exoProperties = {
variantIndex: 1,
} as const

const { optimizationId, variantId, ...unattributedExoProperties } = exoProperties

describe('ExO events', () => {
it.each(['Experience', 'Fragment', 'InlineFragment', 'InlineComponent'])(
'accepts the %s entity kind',
Expand Down Expand Up @@ -87,6 +89,40 @@ describe('ExO events', () => {
expect(InsightsEvent.safeParse(event).success).toBe(true)
})

it.each([
{
type: 'exo_node_view',
viewDurationMs: 3000,
viewId: 'view-123',
},
{ type: 'exo_node_click' },
{
type: 'exo_node_hover',
hoverDurationMs: 1500,
hoverId: 'hover-123',
},
])('parses an unattributed $type event through the Insights event union', (event) => {
expect(
InsightsEvent.safeParse({
...unattributedExoProperties,
...event,
}).success,
).toBe(true)
})

it('preserves attribution for a baseline selection', () => {
const event = {
...exoProperties,
type: 'exo_node_view',
variantIndex: 0,
viewDurationMs: 3000,
viewId: 'view-123',
}

expect(ExoViewEvent.safeParse(event).success).toBe(true)
expect(InsightsEvent.safeParse(event).success).toBe(true)
})

it.each([
{ viewDurationMs: -1, viewId: 'view-123' },
{ viewDurationMs: 1.5, viewId: 'view-123' },
Expand Down
Loading