Skip to content

feat: add public API for manually tracking push notification taps - #35

Merged
gunoooo merged 1 commit into
mainfrom
CLIX-170
Mar 26, 2026
Merged

feat: add public API for manually tracking push notification taps#35
gunoooo merged 1 commit into
mainfrom
CLIX-170

Conversation

@gunoooo

@gunoooo gunoooo commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add ClixNotification.trackPushNotificationTapped(data) public API that allows users to manually report push notification taps
  • Enables push tap tracking for apps using third-party notification libraries (e.g., expo-notifications) where getInitialNotification() returns null because the notification is consumed before the Clix SDK can detect it

Changes

  • NotificationService.trackPushTapped(data) — parses clix payload from raw notification data and tracks the event
  • ClixNotification.trackPushNotificationTapped(data) — public API that delegates to NotificationService

Usage

import Clix from '@clix-so/react-native-sdk';

Clix.Notification.trackPushNotificationTapped(notification.request.content.data);

Test plan

  • Call trackPushNotificationTapped with valid clix payload — event should be tracked
  • Call with missing/invalid clix payload — should throw descriptive error
  • Verify event appears in DB with correct source_type: CLIX

Summary by CodeRabbit

  • New Features
    • Enhanced push notification tracking to capture when users interact with notifications.

@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The changes add push notification tap tracking functionality by introducing trackPushNotificationTapped in the main Clix facade class and trackPushTapped in NotificationService to handle payload validation, session management, and event tracking.

Changes

Cohort / File(s) Summary
Push Notification Tap Tracking
src/core/ClixNotification.ts, src/services/NotificationService.ts
Added public methods for tracking push notification taps. ClixNotification.trackPushNotificationTapped forwards to the notification service. NotificationService.trackPushTapped validates Clix payloads, manages pending message IDs via SessionService, and tracks PUSH_NOTIFICATION_TAPPED events with Clix-specific identifiers.

Possibly related PRs

  • feat: add sourceType to event tracking #27: Modifies push-tap event tracking in NotificationService to pass sourceType ('CLIX'), directly related to the event-tracking flow added in this PR.
  • feat: add session tracking #25: Modifies NotificationService to handle push-tap attribution via SessionService.pendingMessageId management, directly related to the session management logic introduced here.

Suggested reviewers

  • pitzcarraldo
  • nyanxyz
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add public API for manually tracking push notification taps' accurately and specifically describes the main change: adding a new public API method for tracking push notification taps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch CLIX-170

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
coderabbitai Bot requested review from nyanxyz and pitzcarraldo March 26, 2026 08:26

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe670fe2fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

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 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/services/NotificationService.ts`:
- Around line 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.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 03cb93aa-bf0c-4d9a-a159-97f4a7feea57

📥 Commits

Reviewing files that changed from the base of the PR and between 3ada8c3 and fe670fe.

📒 Files selected for processing (2)
  • src/core/ClixNotification.ts
  • src/services/NotificationService.ts

Comment on lines +440 to +456
async trackPushTapped(data: Record<string, any>): Promise<void> {
const clixPayload = this.parseClixPayload(data);
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'
);

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.

@gunoooo
gunoooo merged commit 1a06df1 into main Mar 26, 2026
3 checks passed
@gunoooo
gunoooo deleted the CLIX-170 branch March 26, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant