Skip to content
Open
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
74 changes: 74 additions & 0 deletions src/embed/ts-embed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,80 @@
expect(appInitData.customActions[1].name).toBe('Valid Action');
});
});

test('should trigger CODE_BASED_CUSTOM_ACTION_COUNT mixpanel event with correct count', async () => {
const mockEmbedEventPayload = {
type: EmbedEvent.APP_INIT,
data: {},
};

const customActions = [
{
id: 'action1',
name: 'Custom Action 1',
target: CustomActionTarget.LIVEBOARD,
position: CustomActionsPosition.PRIMARY,
metadataIds: { liveboardIds: ['lb123'] }
},
{
id: 'action2',
name: 'Custom Action 2',
target: CustomActionTarget.VIZ,
position: CustomActionsPosition.MENU,
metadataIds: { vizIds: ['viz456'] }
}
];

const searchEmbed = new SearchEmbed(getRootEl(), {
...defaultViewConfig,
customActions
});

searchEmbed.render();
const mockPort: any = {
postMessage: jest.fn(),
};
await executeAfterWait(() => {
const iframe = getIFrameEl();
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
});

await executeAfterWait(() => {
// Verify that CODE_BASED_CUSTOM_ACTION_COUNT mixpanel event is called with correct count

Check warning on line 1185 in src/embed/ts-embed.spec.ts

View workflow job for this annotation

GitHub Actions / build

Comments may not exceed 80 characters
expect(mockMixPanelEvent).toHaveBeenCalledWith(
MIXPANEL_EVENT.CODE_BASED_CUSTOM_ACTION_COUNT,
{
count: 2,
}
);
});
});

test('should not trigger CODE_BASED_CUSTOM_ACTION_COUNT mixpanel event when no custom actions', async () => {
const mockEmbedEventPayload = {
type: EmbedEvent.APP_INIT,
data: {},
};

const searchEmbed = new SearchEmbed(getRootEl(), {
...defaultViewConfig,
// No customActions provided
});

searchEmbed.render();
const mockPort: any = {
postMessage: jest.fn(),
};
await executeAfterWait(() => {
const iframe = getIFrameEl();
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
});
// Verify that CODE_BASED_CUSTOM_ACTION_COUNT mixpanel event is NOT called when count is 0

Check warning on line 1214 in src/embed/ts-embed.spec.ts

View workflow job for this annotation

GitHub Actions / build

Comments may not exceed 80 characters
expect(mockMixPanelEvent).not.toHaveBeenCalledWith(
MIXPANEL_EVENT.CODE_BASED_CUSTOM_ACTION_COUNT,
expect.anything()
);
});
});

describe('Token fetch fails in cookieless authentication authType', () => {
Expand Down
10 changes: 8 additions & 2 deletions src/embed/ts-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,16 @@ export class TsEmbed {

protected async getDefaultAppInitData(): Promise<DefaultAppInitData> {
const authToken = await this.getAuthTokenForCookielessInit();
const customActionsResult = getCustomActions([
const customActions = [
...(this.viewConfig.customActions || []),
...(this.embedConfig.customActions || [])
]);
];
const customActionsResult = getCustomActions(customActions);
if (customActions.length > 0) {
uploadMixpanelEvent(MIXPANEL_EVENT.CODE_BASED_CUSTOM_ACTION_COUNT, {
count: customActions.length,
});
}
Comment on lines +389 to +393

Choose a reason for hiding this comment

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

medium

It's great that you're adding analytics for code-based custom actions. However, the current implementation sends the count of all custom actions provided, including potentially invalid ones. It would be more accurate and useful for analytics to track the number of valid custom actions that are actually processed and available to the user. You can achieve this by using customActionsResult.actions.length for both the condition and the count.

Suggested change
if (customActions.length > 0) {
uploadMixpanelEvent(MIXPANEL_EVENT.CODE_BASED_CUSTOM_ACTION_COUNT, {
count: customActions.length,
});
}
if (customActionsResult.actions.length > 0) {
uploadMixpanelEvent(MIXPANEL_EVENT.CODE_BASED_CUSTOM_ACTION_COUNT, {
count: customActionsResult.actions.length,
});
}

if (customActionsResult.errors.length > 0) {
this.handleError({
type: 'CUSTOM_ACTION_VALIDATION',
Expand Down
1 change: 1 addition & 0 deletions src/mixpanel-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const MIXPANEL_EVENT = {
VISUAL_SDK_IFRAME_LOAD_PERFORMANCE: 'visual-sdk-iframe-load-performance',
VISUAL_SDK_EMBED_CREATE: 'visual-sdk-embed-create',
VERCEL_INTEGRATION_COMPLETED: 'vercel-integration-completed',
CODE_BASED_CUSTOM_ACTION_COUNT: 'code-based-custom-action-count',
};

let isMixpanelInitialized = false;
Expand Down
Loading