reactnative-plugin-appice 1.7.43 → 1.7.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/TransactionalCampaign.js +60 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/appice/react/AppICEUtils.java +85 -98
- package/android/src/main/java/com/appice/react/AppIceReactPluginModule.java +63 -9
- package/android/src/main/java/com/appice/react/CampaignCampsReceiver.java +16 -2
- package/android/src/main/java/com/appice/react/EnumConstants.java +36 -1
- package/android/src/main/java/com/appice/react/StringConstants.java +2 -0
- package/campaign.js +43 -0
- package/index.js +95 -65
- package/ios/AppICEReactEvent.m +27 -2
- package/ios/AppIceReactPlugin.h +9 -1
- package/ios/AppIceReactPlugin.m +218 -60
- package/ios/AppIceReactPlugin.xcworkspace/xcuserdata/artherajesh.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/package.json +2 -1
- package/reactnative-plugin-appice.podspec +1 -1
- package/example/android/.gradle/7.3.3/checksums/checksums.lock +0 -0
- package/example/android/.gradle/7.3.3/fileChanges/last-build.bin +0 -0
- package/example/android/.gradle/7.3.3/fileHashes/fileHashes.lock +0 -0
- package/example/android/.gradle/7.3.3/gc.properties +0 -0
- package/example/android/.gradle/vcs-1/gc.properties +0 -0
package/campaign.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const { Linking, Platform } = require('react-native');
|
|
2
2
|
|
|
3
3
|
async function handleClickOnPush(campaign) {
|
|
4
|
+
if (campaign && campaign._data) {
|
|
5
|
+
campaign = campaign._data;
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
const url = campaign.actionUrl || campaign.acu || campaign.eurl;
|
|
5
9
|
const actionType = campaign.actionType || campaign.act || campaign.et;
|
|
6
10
|
|
|
@@ -14,6 +18,7 @@ async function handleClickOnPush(campaign) {
|
|
|
14
18
|
if (httpUrls) {
|
|
15
19
|
try {
|
|
16
20
|
if (Platform.OS === 'ios') {
|
|
21
|
+
campaign = normalizeCampaignPayloadForPlatform(campaign);
|
|
17
22
|
return campaign;
|
|
18
23
|
// iOS handle redirection on native side for landing page.
|
|
19
24
|
}
|
|
@@ -31,6 +36,28 @@ async function handleClickOnPush(campaign) {
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
|
|
39
|
+
|
|
40
|
+
const PAYLOAD_KEYS = Object.freeze({
|
|
41
|
+
DATA: 'data',
|
|
42
|
+
MESSAGE: 'message',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// iOS push click payload often nests campaign fields under data.message.
|
|
46
|
+
// Android payload already comes in campaign shape.
|
|
47
|
+
function normalizeCampaignPayloadForPlatform(data) {
|
|
48
|
+
if (!data || typeof data !== 'object') return data;
|
|
49
|
+
if (Platform.OS !== 'ios') return data;
|
|
50
|
+
|
|
51
|
+
const dataNode = data[PAYLOAD_KEYS.DATA];
|
|
52
|
+
if (!dataNode || typeof dataNode !== 'object') return data;
|
|
53
|
+
|
|
54
|
+
const messageNode = dataNode[PAYLOAD_KEYS.MESSAGE];
|
|
55
|
+
if (messageNode && typeof messageNode === 'object') {
|
|
56
|
+
return messageNode;
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
|
|
34
61
|
// ===============================
|
|
35
62
|
// Campaign (merged backward-compatible)
|
|
36
63
|
// ===============================
|
|
@@ -46,6 +73,9 @@ class Campaign {
|
|
|
46
73
|
// if parse fails, keep eventData as-is (object expected)
|
|
47
74
|
data = eventData || {};
|
|
48
75
|
}
|
|
76
|
+
|
|
77
|
+
// Keep app-side listener thin by normalizing payload shape in campaign layer.
|
|
78
|
+
data = normalizeCampaignPayloadForPlatform(data);
|
|
49
79
|
const isLegacy = data && (data.camp_id || data.eurl || data.et || data.abt || data.act || data.acc);
|
|
50
80
|
|
|
51
81
|
if (isLegacy) {
|
|
@@ -200,6 +230,19 @@ class Campaign {
|
|
|
200
230
|
return this._data.customData ? this._data.customData[key] || '' : '';
|
|
201
231
|
}
|
|
202
232
|
|
|
233
|
+
//Action button
|
|
234
|
+
getSelectedActionTitle() {
|
|
235
|
+
return this._data.selectedActionTitle;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
getSelectedActionType() {
|
|
239
|
+
return this._data.selectedActionType;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
getSelectedActionUrl() {
|
|
243
|
+
return this._data.selectedActionUrl;
|
|
244
|
+
}
|
|
245
|
+
|
|
203
246
|
// Convert to JSON
|
|
204
247
|
toJSON() {
|
|
205
248
|
return this._data;
|
package/index.js
CHANGED
|
@@ -25,11 +25,12 @@ export const ACTION_URL = AppIceReactPlugin.ACTION_URL;
|
|
|
25
25
|
export const ACTION_TYPE = AppIceReactPlugin.ACTION_TYPE;
|
|
26
26
|
export const CUSTOMDATA = AppIceReactPlugin.CUSTOMDATA;
|
|
27
27
|
|
|
28
|
+
|
|
28
29
|
const CampaignType = {
|
|
29
30
|
NATIVE: 'NATIVE',
|
|
30
31
|
INAPP: 'INAPP',
|
|
31
32
|
PUSH: 'PUSH',
|
|
32
|
-
|
|
33
|
+
};
|
|
33
34
|
|
|
34
35
|
|
|
35
36
|
var AppICEReact = {
|
|
@@ -40,11 +41,13 @@ var AppICEReact = {
|
|
|
40
41
|
// PUSH
|
|
41
42
|
//========================
|
|
42
43
|
AppICEPushNotificationClicked: AppIceReactPlugin.AppICEPushNotificationClicked,
|
|
44
|
+
AppICEPushNotificationActionButtonClicked: AppIceReactPlugin.AppICEPushNotificationActionButtonClicked,
|
|
43
45
|
|
|
44
46
|
//==========================
|
|
45
47
|
// IN-APP
|
|
46
48
|
//==========================
|
|
47
49
|
AppICEInAppClicked: AppIceReactPlugin.AppICEInAppClicked,
|
|
50
|
+
AppICEHTMLInAppClicked: AppIceReactPlugin.AppICEHTMLInAppClicked,
|
|
48
51
|
|
|
49
52
|
//========================
|
|
50
53
|
// APP-INBOX
|
|
@@ -101,7 +104,14 @@ var AppICEReact = {
|
|
|
101
104
|
AVERAGE_TRANSACTION_AMOUNT: AppIceReactPlugin.AVERAGE_TRANSACTION_AMOUNT,
|
|
102
105
|
FREQUENCY_OF_TRANSACTION: AppIceReactPlugin.FREQUENCY_OF_TRANSACTION,
|
|
103
106
|
TYPE_OF_TRANSACTION: AppIceReactPlugin.TYPE_OF_TRANSACTION,
|
|
104
|
-
|
|
107
|
+
|
|
108
|
+
//====================
|
|
109
|
+
// ACTION BUTTON TYPES
|
|
110
|
+
//====================
|
|
111
|
+
ACTION_TYPE_CUSTOM: AppIceReactPlugin.ACTION_TYPE_CUSTOM,
|
|
112
|
+
ACTION_TYPE_DEEPLINK: AppIceReactPlugin.ACTION_TYPE_DEEPLINK,
|
|
113
|
+
ACTION_TYPE_REPLY: AppIceReactPlugin.ACTION_TYPE_REPLY,
|
|
114
|
+
ACTION_TYPE_REMIND_ME_LATER: AppIceReactPlugin.ACTION_TYPE_REMIND_ME_LATER,
|
|
105
115
|
|
|
106
116
|
//======================
|
|
107
117
|
// LISTENER
|
|
@@ -168,10 +178,10 @@ var AppICEReact = {
|
|
|
168
178
|
AppState.addEventListener('change', (nextAppState) => {
|
|
169
179
|
if (nextAppState === 'active') {
|
|
170
180
|
AppIceReactPlugin.isDeviceReady(true);
|
|
171
|
-
|
|
181
|
+
//AppIceReactPlugin.resumeInApp();
|
|
172
182
|
} else if (nextAppState === 'background') {
|
|
173
|
-
|
|
174
|
-
|
|
183
|
+
AppIceReactPlugin.isDeviceReady(false);
|
|
184
|
+
//AppIceReactPlugin.discardInApp();
|
|
175
185
|
}
|
|
176
186
|
});
|
|
177
187
|
},
|
|
@@ -199,7 +209,7 @@ var AppICEReact = {
|
|
|
199
209
|
if (flush == undefined || flush == null) {
|
|
200
210
|
await AppIceReactPlugin.tagEvent(eventName, props);
|
|
201
211
|
} else {
|
|
202
|
-
const lastEventData
|
|
212
|
+
const lastEventData = await getEventData(LAST_EVENT_KEY)
|
|
203
213
|
|
|
204
214
|
|
|
205
215
|
if (lastEventData != undefined && lastEventData !== eventName) {
|
|
@@ -450,9 +460,9 @@ var AppICEReact = {
|
|
|
450
460
|
callWithCallback('getUserForIds', [userIds], callback);
|
|
451
461
|
},
|
|
452
462
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
463
|
+
/*===================
|
|
464
|
+
GetCampaign
|
|
465
|
+
=====================*/
|
|
456
466
|
|
|
457
467
|
/**
|
|
458
468
|
* getCampaigns
|
|
@@ -462,69 +472,69 @@ var AppICEReact = {
|
|
|
462
472
|
|
|
463
473
|
getCampaigns: function (campType, callback) {
|
|
464
474
|
AppIceReactPlugin.getCampaigns(campType, (campaignArray) => {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
+
const campaigns = campaignArray.map(
|
|
476
|
+
(campaignData) =>
|
|
477
|
+
new Campaign(
|
|
478
|
+
campaignData[CAMP_ID],
|
|
479
|
+
campaignData[ACTION_URL],
|
|
480
|
+
campaignData[ACTION_TYPE],
|
|
481
|
+
campaignData[CUSTOMDATA]
|
|
482
|
+
)
|
|
483
|
+
);
|
|
484
|
+
callback(campaigns);
|
|
475
485
|
});
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
486
|
+
},
|
|
487
|
+
|
|
488
|
+
|
|
479
489
|
|
|
480
490
|
/**
|
|
481
491
|
* getCampaignById
|
|
482
492
|
* @param campId - string
|
|
483
493
|
* @callback -Return a single Campaign object
|
|
484
494
|
*/
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
// Topic Push
|
|
495
|
+
|
|
496
|
+
getCampaignById: function (campId, callback) {
|
|
497
|
+
AppIceReactPlugin.getCampaignById(campId, (campaignData) => {
|
|
498
|
+
const getCampaign = new Campaign(
|
|
499
|
+
campaignData[CAMP_ID],
|
|
500
|
+
campaignData[ACTION_URL],
|
|
501
|
+
campaignData[ACTION_TYPE],
|
|
502
|
+
campaignData[CUSTOMDATA]
|
|
503
|
+
);
|
|
504
|
+
callback(getCampaign);
|
|
505
|
+
});
|
|
506
|
+
},
|
|
507
|
+
|
|
508
|
+
//===============================================
|
|
509
|
+
// Topic Push
|
|
500
510
|
//===============================================
|
|
501
511
|
|
|
502
512
|
isDeviceRegistered: function (callback) {
|
|
503
|
-
|
|
504
|
-
|
|
513
|
+
callWithCallback('isDeviceRegistered', null, callback);
|
|
514
|
+
},
|
|
505
515
|
|
|
506
516
|
setAppLanguage: function (language) {
|
|
507
|
-
|
|
508
|
-
|
|
517
|
+
|
|
518
|
+
AppIceReactPlugin.setAppLanguage(language);
|
|
509
519
|
|
|
510
520
|
},
|
|
511
521
|
|
|
512
522
|
getAppLanguage: function (callback) {
|
|
513
|
-
|
|
514
|
-
|
|
523
|
+
callWithCallback('getAppLanguage', null, callback);
|
|
524
|
+
},
|
|
515
525
|
|
|
516
526
|
setDeviceLanguage: function (language) {
|
|
517
527
|
|
|
518
|
-
|
|
519
|
-
|
|
528
|
+
AppIceReactPlugin.setDeviceLanguage(language);
|
|
529
|
+
|
|
520
530
|
},
|
|
521
531
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
532
|
+
getDeviceLanguage: function (callback) {
|
|
533
|
+
callWithCallback('getDeviceLanguage', null, callback);
|
|
534
|
+
},
|
|
525
535
|
|
|
526
|
-
|
|
527
|
-
|
|
536
|
+
subscribeAppLanguage: function (language) {
|
|
537
|
+
if (Platform.OS === 'android') {
|
|
528
538
|
AppIceReactPlugin.subscribeAppLanguage(language);
|
|
529
539
|
}
|
|
530
540
|
},
|
|
@@ -535,24 +545,44 @@ var AppICEReact = {
|
|
|
535
545
|
}
|
|
536
546
|
},
|
|
537
547
|
|
|
538
|
-
// -------- Custom Topics --------
|
|
539
|
-
setCustomTopic: function (topic) {
|
|
540
|
-
|
|
541
|
-
},
|
|
548
|
+
// -------- Custom Topics --------
|
|
549
|
+
setCustomTopic: function (topic) {
|
|
550
|
+
AppIceReactPlugin.setCustomTopic(topic);
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
removeCustomTopic: function (topic) {
|
|
554
|
+
AppIceReactPlugin.removeCustomTopic(topic);
|
|
555
|
+
},
|
|
556
|
+
|
|
557
|
+
scheduleTransactionalCampaign: function (payloadJson) {
|
|
558
|
+
AppIceReactPlugin.scheduleTransactionalCampaign(payloadJson);
|
|
542
559
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
560
|
+
},
|
|
561
|
+
|
|
562
|
+
/*===================
|
|
563
|
+
INAPP
|
|
564
|
+
=====================*/
|
|
546
565
|
|
|
547
|
-
|
|
548
|
-
|
|
566
|
+
resumeInApp: function () {
|
|
567
|
+
AppIceReactPlugin.resumeInApp();
|
|
568
|
+
},
|
|
549
569
|
|
|
550
|
-
|
|
570
|
+
suspendInApp: function () {
|
|
571
|
+
AppIceReactPlugin.suspendInApp();
|
|
572
|
+
},
|
|
551
573
|
|
|
552
|
-
|
|
553
|
-
|
|
574
|
+
discardInApp: function () {
|
|
575
|
+
AppIceReactPlugin.discardInApp();
|
|
576
|
+
},
|
|
577
|
+
|
|
578
|
+
dismissInApp: function (campType, callback) {
|
|
579
|
+
AppIceReactPlugin.dismissInApp();
|
|
580
|
+
},
|
|
581
|
+
|
|
582
|
+
//campaign enum
|
|
583
|
+
CampaignType,
|
|
554
584
|
};
|
|
555
|
-
|
|
585
|
+
|
|
556
586
|
|
|
557
587
|
|
|
558
588
|
//================================
|
|
@@ -585,8 +615,8 @@ const handleStoredEvents = async (eventName, props) => {
|
|
|
585
615
|
events.push({ eventName, props });
|
|
586
616
|
|
|
587
617
|
// Save the updated events list
|
|
588
|
-
|
|
589
|
-
|
|
618
|
+
// appStorage.set(EVENT_KEY + eventName, JSON.stringify(events));
|
|
619
|
+
// appStorage.set(LAST_EVENT_KEY, eventName);
|
|
590
620
|
|
|
591
621
|
// async Storage
|
|
592
622
|
await AsyncStorage.setItem(EVENT_KEY + eventName, JSON.stringify(events))
|
package/ios/AppICEReactEvent.m
CHANGED
|
@@ -36,7 +36,7 @@ RCT_EXPORT_MODULE();
|
|
|
36
36
|
|
|
37
37
|
- (NSArray<NSString *> *)supportedEvents
|
|
38
38
|
{
|
|
39
|
-
|
|
39
|
+
return @[kAppICEPushNotificationClicked, kAppICEInAppClicked, kAppICEPushNotificationActionButtonClicked,kAppICEHTMLInAppClicked];
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
|
|
@@ -51,7 +51,16 @@ RCT_EXPORT_MODULE();
|
|
|
51
51
|
name:kAppICEInAppClicked
|
|
52
52
|
object:nil];
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
// Observer for the handlePush event
|
|
55
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
56
|
+
selector:@selector(didReceiveHandlePush:)
|
|
57
|
+
name:kAppICEPushNotificationActionButtonClicked
|
|
58
|
+
object:nil];
|
|
59
|
+
|
|
60
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
61
|
+
selector:@selector(InAppHTMLCallback:)
|
|
62
|
+
name:kAppICEHTMLInAppClicked
|
|
63
|
+
object:nil];
|
|
55
64
|
|
|
56
65
|
}
|
|
57
66
|
|
|
@@ -82,5 +91,21 @@ RCT_EXPORT_MODULE();
|
|
|
82
91
|
[self sendEventWithName:kAppICEInAppClicked body:eventDict];
|
|
83
92
|
}
|
|
84
93
|
|
|
94
|
+
//InAppHTMLCallback
|
|
95
|
+
-(void)InAppHTMLCallback:(NSNotification *)event{
|
|
96
|
+
RCTLog(@"from InAppHTMLCallback %@",event);
|
|
97
|
+
NSError * err;
|
|
98
|
+
NSData * jsonUserInfo = [NSJSONSerialization dataWithJSONObject:event.userInfo options:0 error:&err];
|
|
99
|
+
NSMutableDictionary * eventDict = [[NSMutableDictionary alloc]init];
|
|
100
|
+
[eventDict setObject:[[NSString alloc] initWithData:jsonUserInfo encoding:NSUTF8StringEncoding] forKey:kAppICEHTMLInAppClicked];
|
|
101
|
+
RCTLog(@"eventDict %@",eventDict);
|
|
102
|
+
[self sendEventWithName:kAppICEHTMLInAppClicked body:eventDict];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
- (void)didReceiveHandlePush:(NSNotification *)event {
|
|
106
|
+
// Forward the handlePush event (which contains campaign data) to JS
|
|
107
|
+
[self sendEventWithName:kAppICEPushNotificationActionButtonClicked body:event.userInfo];
|
|
108
|
+
}
|
|
109
|
+
|
|
85
110
|
@end
|
|
86
111
|
|
package/ios/AppIceReactPlugin.h
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
#import <UserNotifications/UserNotifications.h>
|
|
3
3
|
static NSString *const kAppICEPushNotificationClicked = @"AppICEPushNotificationClicked";
|
|
4
4
|
static NSString *const kAppICEInAppClicked = @"AppICEInAppClicked";
|
|
5
|
+
static NSString *const kAppICEPushNotificationActionButtonClicked = @"AppICEPushNotificationActionButtonClicked";
|
|
6
|
+
static NSString *const kAppICEHTMLInAppClicked = @"AppICEHTMLInAppClicked";
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
static NSString *const kn = @"APPICE_USER_NAME";
|
|
7
10
|
static NSString *const kem = @"APPICE_USER_EMAIL";
|
|
@@ -35,6 +38,11 @@ static NSString *const ACTION_URL = @"ACTION_URL";
|
|
|
35
38
|
static NSString *const ACTION_TYPE = @"ACTION_TYPE";
|
|
36
39
|
static NSString *const CUSTOMDATA = @"CUSTOMDATA";
|
|
37
40
|
|
|
41
|
+
static NSString *const ACTION_TYPE_CUSTOM = @"ACTION_TYPE_CUSTOM";
|
|
42
|
+
static NSString *const ACTION_TYPE_DEEPLINK = @"ACTION_TYPE_DEEPLINK";
|
|
43
|
+
static NSString *const ACTION_TYPE_REPLY = @"ACTION_TYPE_REPLY";
|
|
44
|
+
static NSString *const ACTION_TYPE_REMIND_ME_LATER = @"ACTION_TYPE_REMIND_ME_LATER";
|
|
45
|
+
|
|
38
46
|
// Custom data
|
|
39
47
|
static NSString *const DEMOGRAPHIC_INFO = @"DEMOGRAPHIC_INFO";
|
|
40
48
|
static NSString *TOP_N_PRODUCTS_VIEWED;
|
|
@@ -59,7 +67,7 @@ static NSString *TYPE_OF_TRANSACTION;
|
|
|
59
67
|
|
|
60
68
|
@interface AppIceReactPlugin : NSObject <RCTBridgeModule,UNUserNotificationCenterDelegate>
|
|
61
69
|
+(void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken;
|
|
62
|
-
+ (void)pushNotificationClicked:(
|
|
70
|
+
+ (void)pushNotificationClicked:(id)userInfo;
|
|
63
71
|
+ (void)pushNotificationReceived:(NSDictionary *)userInfo;
|
|
64
72
|
@end
|
|
65
73
|
|