Skip to content

Commit bd772cd

Browse files
Convert trackInAppOpen.
1 parent 5e0cd11 commit bd772cd

File tree

7 files changed

+56
-7
lines changed

7 files changed

+56
-7
lines changed

InAppClasses.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ enum IterableInAppContentType {
3030
banner = 2,
3131
}
3232

33+
enum IterableInAppLocation {
34+
inApp = 0,
35+
inbox = 1,
36+
}
37+
3338
class IterableEdgeInsets {
3439
top: number
3540
left: number
@@ -169,4 +174,5 @@ export {
169174
IterableHtmlInAppContent,
170175
IterableInboxMetadata,
171176
IterableInAppMessage,
177+
IterableInAppLocation,
172178
}

Iterable.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import { NativeModules, NativeEventEmitter } from 'react-native';
4-
import { IterableInAppMessage, IterableInAppShowResponse } from './InAppClasses'
4+
import { IterableInAppMessage, IterableInAppShowResponse, IterableInAppLocation } from './InAppClasses'
55

66
const RNIterableAPI = NativeModules.RNIterableAPI
77
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI)
@@ -246,6 +246,11 @@ class Iterable {
246246
RNIterableAPI.trackPurchaseWithTotal(total, items, dataFields)
247247
}
248248

249+
static trackInAppOpen(message: IterableInAppMessage, location: IterableInAppLocation) {
250+
console.log("trackInAppOpen")
251+
RNIterableAPI.trackInAppOpenWithMessageId(message.messageId, location)
252+
}
253+
249254
static getInAppMessages(): Promise<Array<IterableInAppMessage>> {
250255
console.log("getInAppMessages");
251256
return RNIterableAPI.getInAppMessages().then((messages: Array<any>) => messages.map (message => {return IterableInAppMessage.fromDict(message)}))

index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class Iterable {
1414
static trackPushOpenWithPayload(payload: any, dataFields: any | null): void
1515
static trackPushOpenWithCampaignId(campaignId: number, templateId: number, messageId: String | null, appAlreadyRunning: Boolean, dataFields: any | null): void
1616
static trackPurchase(total: number, items: Array<IterableCommerceItem>, dataFields: any | null): void
17+
static trackInAppOpen(message: IterableInAppMessage, location: IterableInAppLocation): void
1718
}
1819

1920
export enum PushServicePlatform {
@@ -158,3 +159,9 @@ export class IterableInAppMessage {
158159

159160
static fromDict(dict: any): IterableInAppMessage
160161
}
162+
163+
export enum IterableInAppLocation {
164+
inApp = 0,
165+
inbox = 1,
166+
}
167+

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
IterableHtmlInAppContent,
2626
IterableInboxMetadata,
2727
IterableInAppMessage,
28+
IterableInAppLocation,
2829
} from './InAppClasses';
2930

3031
export {
@@ -44,4 +45,5 @@ export {
4445
IterableHtmlInAppContent,
4546
IterableInboxMetadata,
4647
IterableInAppMessage,
48+
IterableInAppLocation,
4749
};

ios/RNIterableAPI/RNIterableAPI.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ @interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)
4949
items: (NSArray *) items
5050
dataFields: (NSDictionary *) dataFields)
5151

52+
RCT_EXTERN_METHOD(trackInAppOpenWithMessageId: (NSString *) messageId
53+
location: (nonnull NSNumber *) location)
54+
5255
RCT_EXTERN_METHOD(getInAppMessages: (RCTPromiseResolveBlock) resolve
5356
rejecter: (RCTPromiseRejectBlock) reject)
5457

ios/RNIterableAPI/ReactIterableAPI.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,9 @@ class ReactIterableAPI: RCTEventEmitter {
9797
}
9898

9999
@objc(setInAppShowResponse:)
100-
func set(inAppShowResponse: NSNumber) {
100+
func set(inAppShowResponse number: NSNumber) {
101101
ITBInfo()
102-
if let value = inAppShowResponse as? Int {
103-
self.inAppShowResponse = InAppShowResponse(rawValue: value) ?? .show
104-
} else {
105-
self.inAppShowResponse = .show
106-
}
102+
self.inAppShowResponse = InAppShowResponse.from(number: number)
107103
inAppDelegateSemapohore.signal()
108104
}
109105

@@ -172,6 +168,16 @@ class ReactIterableAPI: RCTEventEmitter {
172168
items: items.compactMap(CommerceItem.from(dict:)),
173169
dataFields: dataFields)
174170
}
171+
172+
@objc(trackInAppOpenWithMessageId:location:)
173+
func trackInAppOpen(messageId: String, location number: NSNumber) {
174+
ITBInfo()
175+
guard let message = IterableAPI.inAppManager.getMessage(withId: messageId) else {
176+
ITBError("Could not find message with id: \(messageId)")
177+
return
178+
}
179+
IterableAPI.track(inAppOpen: message, location: InAppLocation.from(number: number))
180+
}
175181

176182
@objc(getInAppMessages:rejecter:)
177183
func getInAppMessages(resolver: RCTPromiseResolveBlock, rejecter: RCTPromiseRejectBlock) {

ios/RNIterableAPI/Serialization.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,23 @@ extension IterableInAppMessage {
141141
return dict
142142
}
143143
}
144+
145+
extension InAppLocation {
146+
static func from(number: NSNumber) -> InAppLocation {
147+
if let value = number as? Int {
148+
return InAppLocation(rawValue: value) ?? .inApp
149+
} else {
150+
return .inApp
151+
}
152+
}
153+
}
154+
155+
extension InAppShowResponse {
156+
static func from(number: NSNumber) -> InAppShowResponse {
157+
if let value = number as? Int {
158+
return InAppShowResponse(rawValue: value) ?? .show
159+
} else {
160+
return .show
161+
}
162+
}
163+
}

0 commit comments

Comments
 (0)