Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion pages/analytics/hooks/useVideoLayerData.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,24 @@ export function groupRows( rows, layerType, configIndex ) {
// path the parent uses so a raw composite UUID never reaches
// the rail. Falls back to a generic ordinal "<TypeLabel> #N"
// when nothing usable.
const rawSubName = md.product_name || row.layer_name || '';
let rawSubName = md.product_name || row.layer_name || '';
// The hotspot tracker packs the parent layer name, a separator
// dash, and "Hotspot N" into layer_name. The rail's card title
// already shows the parent, so that prefix is pure repetition
// and, once the row is truncated, it hides the "Hotspot N" that
// actually names the row. Drop the parent prefix (and the
// separator after it), keeping only the hotspot's own label.
// Woo rows carry a bare product_name and never match this, so
// they are left alone.
if (
! md.product_name &&
md.parent_layer_name &&
rawSubName.startsWith( md.parent_layer_name )
) {
rawSubName = rawSubName
.slice( md.parent_layer_name.length )
.replace( /^[\s\p{Pd}]+/u, '' );
}
Comment thread
subodhr258 marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The separator cleanup is greedy across dashes, so it can also eat a dash that belongs to the hotspot's own label.

/^[\s\p{Pd}]+/u consumes every leading whitespace/dash character, not just the one separator. A hotspot named -50% off inside a layer named Summer sale is tracked as Summer sale — -50% off (hotspotLayerManager.js composes ${parentLayerName} — ${subLabel}). After slice() the remainder is " — -50% off", and the character class then swallows space + em dash + space and the label's own hyphen, so the rail row reads 50% off — the opposite meaning. Same for something like —Limited—.

Anchoring the strip to a single separator occurrence keeps the label intact, e.g.:

rawSubName = rawSubName
	.slice( md.parent_layer_name.length )
	.replace( /^\s*\p{Pd}\s*/u, '' );

(or only strip when the composite actually matches parent + SEP). Minor/edge-case — everything else in the change looks right to me: the ! md.product_name guard correctly exempts Woo, startsWith avoids touching unrelated names, parent_layer_name landed in the same commit as the composite name so there's no historical-data gap, and an empty result still falls through to the "<Type> #N" ordinal.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b91bdab. Went with your "only strip when the composite actually matches parent + SEP" option, which resolves this greedy-dash case and the Copilot prefix-collision case in one check. The strip now matches the exact <parent> — prefix and slices just that — no character-class replace — so a label that begins with its own dash keeps it: Summer sale — -50% off -> -50% off, not 50% off.

The separator is now a module constant HOTSPOT_NAME_SEPARATOR = ' — ' with a comment pointing at hotspotLayerManager.js:213, since that is the source of truth for the composite. Added two tests (leading-dash and prefix-collision); both fail on the old logic and pass now. 15/15 in the suite.

let subName;
if (
rawSubName &&
Expand Down
67 changes: 67 additions & 0 deletions pages/analytics/hooks/useVideoLayerData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,70 @@ describe( 'groupRows — a hotspot reports its own viewed, never the layer\'s',
expect( byName[ 'Added yesterday' ] ).toEqual( [ 1, 1 ] );
} );
} );

describe( 'groupRows — hotspot sub-name drops the redundant parent prefix', () => {
// The tracker writes each hotspot event's layer_name as the parent layer
// name, a separator dash, then "Hotspot N" (e.g. the parent "Hotspot layer
// at 4.59s" followed by " <dash> Hotspot 2"). The rail already shows the
// parent as its card title, so the row must read just "Hotspot N". SEP is
// built from a code point so no literal em dash lives in this file.
const SEP = ` ${ String.fromCharCode( 0x2014 ) } `;
const PARENT = 'Hotspot layer at 4.59s';
const base = { layer_type: 'hotspot', page_url: 'https://example.com', timestamp: 4.59 };
const parentRow = {
...base,
layer_id: 'h-1',
layer_name: PARENT,
viewed: 2, clicked: 1, hovered: 2,
conversion_rate: 50,
layer_metadata: JSON.stringify( { parent_layer_id: 'h-1', parent_layer_name: PARENT } ),
};
const subRow = ( suffix, label, index ) => ( {
...base,
layer_id: `h-1::${ suffix }`,
layer_name: `${ PARENT }${ SEP }${ label }`,
viewed: 1, clicked: 0, hovered: 0,
conversion_rate: 0,
layer_metadata: JSON.stringify( {
parent_layer_id: 'h-1',
parent_layer_name: PARENT,
hotspot_index: index,
} ),
} );

it( 'strips the parent name and separator, leaving only "Hotspot N"', () => {
const rows = [ parentRow, subRow( 'a', 'Hotspot 1', 0 ), subRow( 'b', 'Hotspot 2', 1 ) ];
const [ parent ] = groupRows( rows, 'hotspot', OPEN_CONFIG );
expect( parent.sub_hotspots.map( ( s ) => s.name ).sort() ).toEqual( [ 'Hotspot 1', 'Hotspot 2' ] );
} );

it( 'leaves a Woo product name untouched (guarded by product_name)', () => {
const wooParent = {
...parentRow,
layer_type: 'woo',
layer_id: 'w-1',
layer_name: 'Woo layer at 9.90s',
layer_metadata: JSON.stringify( { parent_layer_id: 'w-1', parent_layer_name: 'Woo layer at 9.90s' } ),
};
const wooSub = {
...base,
layer_type: 'woo',
layer_id: 'w-1::p1',
layer_name: 'Lamp',
viewed: 0, hovered: 1, added_to_cart: 0, conversion_rate: 0,
layer_metadata: JSON.stringify( { parent_layer_id: 'w-1', product_id: 1, product_name: 'Lamp' } ),
};
const [ parent ] = groupRows( [ wooParent, wooSub ], 'woo', OPEN_CONFIG );
expect( parent.sub_hotspots.map( ( s ) => s.name ) ).toEqual( [ 'Lamp' ] );
} );

it( 'keeps a sub name that does not start with the parent prefix', () => {
const custom = {
...subRow( 'c', 'ignored', 2 ),
layer_name: 'Buy now',
layer_metadata: JSON.stringify( { parent_layer_id: 'h-1', parent_layer_name: PARENT } ),
};
const [ parent ] = groupRows( [ parentRow, custom ], 'hotspot', OPEN_CONFIG );
expect( parent.sub_hotspots.map( ( s ) => s.name ) ).toContain( 'Buy now' );
} );
} );
Loading