Skip to content

Commit 12e242d

Browse files
Convert trackInAppClose
1 parent d7bb371 commit 12e242d

File tree

7 files changed

+77
-5
lines changed

7 files changed

+77
-5
lines changed

InAppClasses.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ enum IterableInAppLocation {
3535
inbox = 1,
3636
}
3737

38+
enum IterableInAppCloseSource {
39+
back = 0,
40+
link = 1,
41+
unknown = 100,
42+
}
43+
3844
class IterableEdgeInsets {
3945
top: number
4046
left: number
@@ -175,4 +181,5 @@ export {
175181
IterableInboxMetadata,
176182
IterableInAppMessage,
177183
IterableInAppLocation,
184+
IterableInAppCloseSource,
178185
}

Iterable.ts

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

33
import { NativeModules, NativeEventEmitter } from 'react-native';
4-
import { IterableInAppMessage, IterableInAppShowResponse, IterableInAppLocation } from './InAppClasses'
4+
import {
5+
IterableInAppMessage,
6+
IterableInAppShowResponse,
7+
IterableInAppLocation,
8+
IterableInAppCloseSource,
9+
} from './InAppClasses'
510

611
const RNIterableAPI = NativeModules.RNIterableAPI
712
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI)
@@ -267,6 +272,18 @@ class Iterable {
267272
RNIterableAPI.trackInAppClick(message.messageId, location, clickedUrl)
268273
}
269274

275+
/**
276+
*
277+
* @param {IterableInAppMessage} message
278+
* @param {IterableInAppLocation} location
279+
* @param {IterableInAppCloseSource} source
280+
* @param {String} clickedUrl
281+
*/
282+
static trackInAppClose(message: IterableInAppMessage, location: IterableInAppLocation, source: IterableInAppCloseSource, clickedUrl: String) {
283+
console.log("trackInAppClose")
284+
RNIterableAPI.trackInAppClose(message.messageId, location, source, clickedUrl)
285+
}
286+
270287
static getInAppMessages(): Promise<Array<IterableInAppMessage>> {
271288
console.log("getInAppMessages");
272289
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
@@ -165,3 +165,10 @@ export enum IterableInAppLocation {
165165
inbox = 1,
166166
}
167167

168+
export enum IterableInAppCloseSource {
169+
back = 0,
170+
link = 1,
171+
unknown = 100,
172+
}
173+
174+

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
IterableInboxMetadata,
2727
IterableInAppMessage,
2828
IterableInAppLocation,
29+
IterableInAppCloseSource,
2930
} from './InAppClasses';
3031

3132
export {
@@ -46,4 +47,5 @@ export {
4647
IterableInboxMetadata,
4748
IterableInAppMessage,
4849
IterableInAppLocation,
50+
IterableInAppCloseSource,
4951
};

ios/RNIterableAPI/RNIterableAPI.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ @interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)
5656
location: (nonnull NSNumber *) location
5757
clickedUrl: (nonnull NSString *) clickedUrl)
5858

59+
RCT_EXTERN_METHOD(trackInAppClose: (nonnull NSString *) messageId
60+
location: (nonnull NSNumber *) location
61+
source: (nonnull NSNumber *) source
62+
clickedUrl: (nonnull NSString *) clickedUrl)
63+
5964
RCT_EXTERN_METHOD(getInAppMessages: (RCTPromiseResolveBlock) resolve
6065
rejecter: (RCTPromiseRejectBlock) reject)
6166

ios/RNIterableAPI/ReactIterableAPI.swift

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,48 @@ class ReactIterableAPI: RCTEventEmitter {
170170
}
171171

172172
@objc(trackInAppOpen:location:)
173-
func trackInAppOpen(messageId: String, location number: NSNumber) {
173+
func trackInAppOpen(messageId: String,
174+
location locationNumber: NSNumber) {
174175
ITBInfo()
175176
guard let message = IterableAPI.inAppManager.getMessage(withId: messageId) else {
176177
ITBError("Could not find message with id: \(messageId)")
177178
return
178179
}
179-
IterableAPI.track(inAppOpen: message, location: InAppLocation.from(number: number))
180+
IterableAPI.track(inAppOpen: message, location: InAppLocation.from(number: locationNumber))
180181
}
181182

182183
@objc(trackInAppClick:location:clickedUrl:)
183-
func trackInAppClick(messageId: String, location number: NSNumber, clickedUrl: String) {
184+
func trackInAppClick(messageId: String,
185+
location locationNumber: NSNumber,
186+
clickedUrl: String) {
184187
ITBInfo()
185188
guard let message = IterableAPI.inAppManager.getMessage(withId: messageId) else {
186189
ITBError("Could not find message with id: \(messageId)")
187190
return
188191
}
189-
IterableAPI.track(inAppClick: message, location: InAppLocation.from(number: number), clickedUrl: clickedUrl)
192+
IterableAPI.track(inAppClick: message, location: InAppLocation.from(number: locationNumber), clickedUrl: clickedUrl)
193+
}
194+
195+
@objc(trackInAppClose:location:source:clickedUrl:)
196+
func trackInAppClose(messageId: String,
197+
location locationNumber: NSNumber,
198+
source sourceNumber: NSNumber,
199+
clickedUrl: String) {
200+
ITBInfo()
201+
guard let message = IterableAPI.inAppManager.getMessage(withId: messageId) else {
202+
ITBError("Could not find message with id: \(messageId)")
203+
return
204+
}
205+
if let inAppCloseSource = InAppCloseSource.from(number: sourceNumber) {
206+
IterableAPI.track(inAppClose: message,
207+
location: InAppLocation.from(number: locationNumber),
208+
source: inAppCloseSource,
209+
clickedUrl: clickedUrl)
210+
} else {
211+
IterableAPI.track(inAppClose: message,
212+
location: InAppLocation.from(number: locationNumber),
213+
clickedUrl: clickedUrl)
214+
}
190215
}
191216

192217
@objc(getInAppMessages:rejecter:)

ios/RNIterableAPI/Serialization.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ extension InAppLocation {
152152
}
153153
}
154154

155+
extension InAppCloseSource {
156+
static func from(number: NSNumber) -> InAppCloseSource? {
157+
guard let value = number as? Int else {
158+
return nil
159+
}
160+
return InAppCloseSource(rawValue: value)
161+
}
162+
}
163+
155164
extension InAppShowResponse {
156165
static func from(number: NSNumber) -> InAppShowResponse {
157166
if let value = number as? Int {

0 commit comments

Comments
 (0)