Skip to content

Commit 447ba16

Browse files
committed
Merge branch 'master' into MOB-1326-track-event
# Conflicts: # index.d.ts
2 parents 3d5a82a + 6a0c456 commit 447ba16

File tree

7 files changed

+172
-10
lines changed

7 files changed

+172
-10
lines changed

InAppClasses.ts

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

38+
enum IterableInAppCloseSource {
39+
back = 0,
40+
link = 1,
41+
unknown = 100,
42+
}
43+
44+
enum IterableInAppDeleteSource {
45+
inboxSwipe = 0,
46+
deleteButton = 1,
47+
unknown = 100,
48+
}
49+
3850
class IterableEdgeInsets {
3951
top: number
4052
left: number
@@ -175,4 +187,6 @@ export {
175187
IterableInboxMetadata,
176188
IterableInAppMessage,
177189
IterableInAppLocation,
190+
IterableInAppCloseSource,
191+
IterableInAppDeleteSource,
178192
}

Iterable.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
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+
IterableInAppDeleteSource,
10+
} from './InAppClasses'
511

612
const RNIterableAPI = NativeModules.RNIterableAPI
713
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI)
@@ -243,12 +249,51 @@ class Iterable {
243249
*/
244250
static trackPurchase(total: number, items: Array<IterableCommerceItem>, dataFields: any | null) {
245251
console.log("trackPurchase")
246-
RNIterableAPI.trackPurchaseWithTotal(total, items, dataFields)
252+
RNIterableAPI.trackPurchase(total, items, dataFields)
247253
}
248254

255+
/**
256+
*
257+
* @param {IterableInAppMessage} message
258+
* @param {IterableInAppLocation} location
259+
*/
249260
static trackInAppOpen(message: IterableInAppMessage, location: IterableInAppLocation) {
250261
console.log("trackInAppOpen")
251-
RNIterableAPI.trackInAppOpenWithMessageId(message.messageId, location)
262+
RNIterableAPI.trackInAppOpen(message.messageId, location)
263+
}
264+
265+
/**
266+
*
267+
* @param {IterableInAppMessage} message
268+
* @param {IterableInAppLocation} location
269+
* @param {String} clickedUrl
270+
*/
271+
static trackInAppClick(message: IterableInAppMessage, location: IterableInAppLocation, clickedUrl: String) {
272+
console.log("trackInAppClick")
273+
RNIterableAPI.trackInAppClick(message.messageId, location, clickedUrl)
274+
}
275+
276+
/**
277+
*
278+
* @param {IterableInAppMessage} message
279+
* @param {IterableInAppLocation} location
280+
* @param {IterableInAppCloseSource} source
281+
* @param {String} clickedUrl
282+
*/
283+
static trackInAppClose(message: IterableInAppMessage, location: IterableInAppLocation, source: IterableInAppCloseSource, clickedUrl: String) {
284+
console.log("trackInAppClose")
285+
RNIterableAPI.trackInAppClose(message.messageId, location, source, clickedUrl)
286+
}
287+
288+
/**
289+
*
290+
* @param {IterableInAppMessage} message
291+
* @param {IterableInAppLocation} location
292+
* @param {IterableInAppDeleteSource} source
293+
*/
294+
static inAppConsume(message: IterableInAppMessage, location: IterableInAppLocation, source: IterableInAppDeleteSource) {
295+
console.log("inAppConsume")
296+
RNIterableAPI.inAppConsume(message.messageId, location, source)
252297
}
253298

254299
static getInAppMessages(): Promise<Array<IterableInAppMessage>> {

index.d.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ export class Iterable {
88
static disableDeviceForAllUsers(): void
99
static getInAppMessages(): void
1010
static getLastPushPayload(): Promise<any | null>
11-
static getLastPushPayload(): Promise<any | null>
1211
static getAttributionInfo(): Promise<IterableAttributionInfo | null>
1312
static setAttributionInfo(attributionInfo?: IterableAttributionInfo): void
1413
static trackPushOpenWithPayload(payload: any, dataFields: any | null): void
1514
static trackPushOpenWithCampaignId(campaignId: number, templateId: number, messageId: String | null, appAlreadyRunning: Boolean, dataFields: any | null): void
1615
static trackPurchase(total: number, items: Array<IterableCommerceItem>, dataFields: any | null): void
1716
static trackInAppOpen(message: IterableInAppMessage, location: IterableInAppLocation): void
17+
static trackInAppClick(message: IterableInAppMessage, location: IterableInAppLocation, clickedUrl: String): void
18+
static inAppConsume(message: IterableInAppMessage, location: IterableInAppLocation, source: IterableInAppDeleteSource): void
1819
static trackEvent(name: String, dataFields: any | null): void
1920
}
2021

@@ -166,3 +167,16 @@ export enum IterableInAppLocation {
166167
inbox = 1,
167168
}
168169

170+
export enum IterableInAppCloseSource {
171+
back = 0,
172+
link = 1,
173+
unknown = 100,
174+
}
175+
176+
export enum IterableInAppDeleteSource {
177+
inboxSwipe = 0,
178+
deleteButton = 1,
179+
unknown = 100,
180+
}
181+
182+

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
IterableInboxMetadata,
2727
IterableInAppMessage,
2828
IterableInAppLocation,
29+
IterableInAppCloseSource,
30+
IterableInAppDeleteSource,
2931
} from './InAppClasses';
3032

3133
export {
@@ -46,4 +48,6 @@ export {
4648
IterableInboxMetadata,
4749
IterableInAppMessage,
4850
IterableInAppLocation,
51+
IterableInAppCloseSource,
52+
IterableInAppDeleteSource,
4953
};

ios/RNIterableAPI/RNIterableAPI.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,26 @@ @interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)
4545
appAlreadyRunning: (BOOL) appAlreadyRunning
4646
dataFields: (NSDictionary *) dataFields)
4747

48-
RCT_EXTERN_METHOD(trackPurchaseWithTotal: (nonnull NSNumber *) total
48+
RCT_EXTERN_METHOD(trackPurchase: (nonnull NSNumber *) total
4949
items: (NSArray *) items
5050
dataFields: (NSDictionary *) dataFields)
5151

52-
RCT_EXTERN_METHOD(trackInAppOpenWithMessageId: (NSString *) messageId
52+
RCT_EXTERN_METHOD(trackInAppOpen: (NSString *) messageId
5353
location: (nonnull NSNumber *) location)
5454

55+
RCT_EXTERN_METHOD(trackInAppClick: (nonnull NSString *) messageId
56+
location: (nonnull NSNumber *) location
57+
clickedUrl: (nonnull NSString *) clickedUrl)
58+
59+
RCT_EXTERN_METHOD(trackInAppClose: (nonnull NSString *) messageId
60+
location: (nonnull NSNumber *) location
61+
source: (nonnull NSNumber *) source
62+
clickedUrl: (nonnull NSString *) clickedUrl)
63+
64+
RCT_EXTERN_METHOD(inAppConsume: (nonnull NSString *) messageId
65+
location: (nonnull NSNumber *) location
66+
source: (nonnull NSNumber *) source)
67+
5568
RCT_EXTERN_METHOD(getInAppMessages: (RCTPromiseResolveBlock) resolve
5669
rejecter: (RCTPromiseRejectBlock) reject)
5770

ios/RNIterableAPI/ReactIterableAPI.swift

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class ReactIterableAPI: RCTEventEmitter {
159159
IterableAPI.track(pushOpen: campaignId, templateId: templateId, messageId: messageId, appAlreadyRunning: appAlreadyRunning, dataFields: dataFields)
160160
}
161161

162-
@objc(trackPurchaseWithTotal:items:dataFields:)
162+
@objc(trackPurchase:items:dataFields:)
163163
func trackPurchase(total: NSNumber,
164164
items: [[AnyHashable: Any]],
165165
dataFields: [AnyHashable: Any]?) {
@@ -169,14 +169,68 @@ class ReactIterableAPI: RCTEventEmitter {
169169
dataFields: dataFields)
170170
}
171171

172-
@objc(trackInAppOpenWithMessageId:location:)
173-
func trackInAppOpen(messageId: String, location number: NSNumber) {
172+
@objc(trackInAppOpen:location:)
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))
181+
}
182+
183+
@objc(trackInAppClick:location:clickedUrl:)
184+
func trackInAppClick(messageId: String,
185+
location locationNumber: NSNumber,
186+
clickedUrl: String) {
187+
ITBInfo()
188+
guard let message = IterableAPI.inAppManager.getMessage(withId: messageId) else {
189+
ITBError("Could not find message with id: \(messageId)")
190+
return
191+
}
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+
}
215+
}
216+
217+
@objc(inAppConsume:location:source:)
218+
func inAppConsume(messageId: String,
219+
location locationNumber: NSNumber,
220+
source sourceNumber: NSNumber) {
221+
ITBInfo()
222+
guard let message = IterableAPI.inAppManager.getMessage(withId: messageId) else {
223+
ITBError("Could not find message with id: \(messageId)")
224+
return
225+
}
226+
if let inAppDeleteSource = InAppDeleteSource.from(number: sourceNumber) {
227+
IterableAPI.inAppConsume(message: message,
228+
location: InAppLocation.from(number: locationNumber),
229+
source: inAppDeleteSource)
230+
} else {
231+
IterableAPI.inAppConsume(message: message,
232+
location: InAppLocation.from(number: locationNumber))
233+
}
180234
}
181235

182236
@objc(getInAppMessages:rejecter:)

ios/RNIterableAPI/Serialization.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ 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+
164+
extension InAppDeleteSource {
165+
static func from(number: NSNumber) -> InAppDeleteSource? {
166+
guard let value = number as? Int else {
167+
return nil
168+
}
169+
return InAppDeleteSource(rawValue: value)
170+
}
171+
}
172+
155173
extension InAppShowResponse {
156174
static func from(number: NSNumber) -> InAppShowResponse {
157175
if let value = number as? Int {

0 commit comments

Comments
 (0)