Skip to content
Closed
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 @@ -593,6 +593,15 @@ public boolean handleIterableCustomAction(@NonNull IterableAction action, @NonNu
eventDataJson.put("context", actionContextJson);
WritableMap eventData = Serialization.convertJsonToMap(eventDataJson);
sendEvent(EventName.handleCustomActionCalled.name(), eventData);

// Emit notification opened event when source is push
if (actionContext.source == IterableActionContext.Source.PUSH) {
JSONObject notifEventDataJson = new JSONObject();
notifEventDataJson.put("action", actionJson);
notifEventDataJson.put("context", actionContextJson);
WritableMap notifEventData = Serialization.convertJsonToMap(notifEventDataJson);
sendEvent(EventName.handleNotificationOpenedCalled.name(), notifEventData);
}
} catch (JSONException e) {
IterableLogger.e(TAG, "Failed handling custom action");
}
Expand Down Expand Up @@ -632,6 +641,16 @@ public boolean handleIterableURL(@NonNull Uri uri, @NonNull IterableActionContex
eventDataJson.put("context", actionContextJson);
WritableMap eventData = Serialization.convertJsonToMap(eventDataJson);
sendEvent(EventName.handleUrlCalled.name(), eventData);

// Emit notification opened event when source is push
if (actionContext.source == IterableActionContext.Source.PUSH) {
JSONObject notifEventDataJson = new JSONObject();
JSONObject actionJson = Serialization.actionToJson(actionContext.action);
notifEventDataJson.put("action", actionJson);
notifEventDataJson.put("context", actionContextJson);
WritableMap notifEventData = Serialization.convertJsonToMap(notifEventDataJson);
sendEvent(EventName.handleNotificationOpenedCalled.name(), notifEventData);
}
} catch (JSONException e) {
IterableLogger.e(TAG, e.getLocalizedMessage());
}
Expand Down Expand Up @@ -808,6 +827,7 @@ enum EventName {
handleCustomActionCalled,
handleEmbeddedMessageUpdateCalled,
handleEmbeddedMessagingDisabledCalled,
handleNotificationOpenedCalled,
handleInAppCalled,
handleUrlCalled,
receivedIterableEmbeddedMessagesChanged,
Expand Down
24 changes: 24 additions & 0 deletions ios/RNIterableAPI/ReactIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import React
case handleAuthFailureCalled
case handleEmbeddedMessageUpdateCalled
case handleEmbeddedMessagingDisabledCalled
case handleNotificationOpenedCalled
}

@objc public static var supportedEvents: [String] {
Expand Down Expand Up @@ -710,6 +711,18 @@ extension ReactIterableAPI: IterableURLDelegate {
"url": url.absoluteString,
"context": contextDict,
] as [String: Any])

// Emit notification opened event when source is push
if context.source == .push {
let actionDict = ReactIterableAPI.actionToDictionary(action: context.action)
delegate?.sendEvent(
withName: EventName.handleNotificationOpenedCalled.rawValue,
body: [
"action": actionDict,
"context": contextDict,
] as [String: Any])
}

return true
}

Expand Down Expand Up @@ -749,6 +762,17 @@ extension ReactIterableAPI: IterableCustomActionDelegate {
"action": actionDict,
"context": contextDict,
])

// Emit notification opened event when source is push
if context.source == .push {
delegate?.sendEvent(
withName: EventName.handleNotificationOpenedCalled.rawValue,
body: [
"action": actionDict,
"context": contextDict,
])
}

return true
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/core/classes/Iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,9 @@ export class Iterable {
RNEventEmitter.removeAllListeners(
IterableEventName.handleEmbeddedMessagingDisabledCalled
);
RNEventEmitter.removeAllListeners(
IterableEventName.handleNotificationOpenedCalled
);
}

/**
Expand Down Expand Up @@ -1109,6 +1112,17 @@ export class Iterable {
);
}
}

if (Iterable.savedConfig.notificationOpenedHandler) {
RNEventEmitter.addListener(
IterableEventName.handleNotificationOpenedCalled,
(dict) => {
const action = IterableAction.fromDict(dict.action);
const context = IterableActionContext.fromDict(dict.context);
Iterable.savedConfig.notificationOpenedHandler!(action, context);
}
);
}
}

/**
Expand Down
27 changes: 27 additions & 0 deletions src/core/classes/IterableConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,30 @@ export class IterableConfig {
*/
onEmbeddedMessagingDisabled?: () => void;

/**
* A callback function that is called when a push notification is opened/pressed.
*
* This callback fires for all push notification opens, regardless of whether
* the notification has a URL action, custom action, or no action at all.
* It provides access to the raw action and context data from the notification.
*
* @param action - The action associated with the notification press.
* @param context - The context in which the action was triggered, including the source.
*
* @example
* ```typescript
* const config = new IterableConfig();
* config.notificationOpenedHandler = (action, context) => {
* console.log('Notification opened:', action, context);
* };
* Iterable.initialize('<YOUR_API_KEY>', config);
* ```
*/
notificationOpenedHandler?: (
action: IterableAction,
context: IterableActionContext
) => void;

/**
* Converts the IterableConfig instance to a dictionary object.
*
Expand Down Expand Up @@ -440,6 +464,9 @@ export class IterableConfig {
encryptionEnforced: this.encryptionEnforced,
retryPolicy: this.retryPolicy,
enableEmbeddedMessaging: this.enableEmbeddedMessaging,
// eslint-disable-next-line eqeqeq
notificationOpenedHandlerPresent:
this.notificationOpenedHandler != undefined,
};
}
}
2 changes: 2 additions & 0 deletions src/core/enums/IterableEventName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ export enum IterableEventName {
handleEmbeddedMessageUpdateCalled = 'handleEmbeddedMessageUpdateCalled',
/** Event that fires when embedded messaging is disabled */
handleEmbeddedMessagingDisabledCalled = 'handleEmbeddedMessagingDisabledCalled',
/** Event that fires when a push notification is opened/pressed */
handleNotificationOpenedCalled = 'handleNotificationOpenedCalled',
}
Loading