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
9 changes: 9 additions & 0 deletions src/core/ClixNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ export class ClixNotification {
}
}

async trackPushNotificationTapped(data: Record<string, any>): Promise<void> {
await Clix.initCoordinator.waitForInitialization();
const notificationService = Clix.shared?.notificationService;
if (!notificationService) {
throw new Error('Notification service is not initialized');
}
await notificationService.trackPushTapped(data);
}

async onMessage(handler?: MessageHandler): Promise<void> {
try {
await Clix.initCoordinator.waitForInitialization();
Expand Down
23 changes: 23 additions & 0 deletions src/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,29 @@ export class NotificationService {
}
}

async trackPushTapped(data: Record<string, any>): Promise<void> {
const clixPayload = this.parseClixPayload(data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Accept tap payloads without title/body fields

trackPushTapped reuses parseClixPayload, which rejects payloads unless message_id, title, and body are all present; for the third-party notification use case this API targets, tap callbacks often provide only tracking identifiers in data while title/body live outside that object, so this path now throws and drops PUSH_NOTIFICATION_TAPPED events instead of recording them. Because eventService.trackEvent only needs the IDs, this validation is stricter than necessary for manual tap tracking and breaks the new feature for those payload shapes.

Useful? React with 👍 / 👎.

if (!clixPayload) {
throw new Error(
'No valid Clix payload found in notification data. ' +
"Ensure the notification data contains a 'clix' key with message_id, title, and body."
);
}
this.sessionService?.setPendingMessageId(clixPayload.messageId);
await this.eventService.trackEvent(
'PUSH_NOTIFICATION_TAPPED',
{},
clixPayload.messageId,
clixPayload.userJourneyId,
clixPayload.userJourneyNodeId,
'CLIX'
);
Comment on lines +440 to +456

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Make tap tracking idempotent across manual and automatic handlers.

This new path always emits PUSH_NOTIFICATION_TAPPED, but the SDK already does the same from handleNotificationOpenedApp, handleInitialNotification, and handleNotificationEvent. Because Clix.Notification.trackPushNotificationTapped() only runs after initialization, a cold-start tap that handleInitialNotification() already captured can be counted a second time when the app also calls this API. Please route both paths through one messageId-based dedupe helper.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/NotificationService.ts` around lines 440 - 456, trackPushTapped
currently always emits PUSH_NOTIFICATION_TAPPED and can double-count taps
already recorded by handleNotificationOpenedApp / handleInitialNotification /
handleNotificationEvent or by Clix.Notification.trackPushNotificationTapped();
modify trackPushTapped to call a shared dedupe helper (e.g.,
ensureNotificationTapNotTracked(messageId) or reuse existing sessionService
pending-message logic) that checks the messageId and returns early if already
tracked, otherwise marks it tracked and proceeds to call eventService.trackEvent
with the same parameters; reference the trackPushTapped method and the other
handlers (handleNotificationOpenedApp, handleInitialNotification,
handleNotificationEvent, Clix.Notification.trackPushNotificationTapped) so the
dedupe helper is used by both code paths to ensure idempotent tracking.

ClixLogger.debug(
'PUSH_NOTIFICATION_TAPPED event tracked:',
clixPayload.messageId
);
}

private async trackPushTappedEvent(
payload: ClixPushNotificationPayload
): Promise<void> {
Expand Down
Loading