@adobe/react-native-aepmessaging 1.0.0-beta.2 → 1.0.0

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.
@@ -18,5 +18,5 @@ Pod::Spec.new do |s|
18
18
  s.requires_arc = true
19
19
 
20
20
  s.dependency "React"
21
- s.dependency "AEPMessaging", "~>1.0"
21
+ s.dependency "AEPMessaging", "~>1.1"
22
22
  end
package/README.md CHANGED
@@ -1,64 +1,78 @@
1
-
2
1
  # React Native Adobe Experience Platform Messaging Extension
3
2
 
4
- [![npm version](https://badge.fury.io/js/%40adobe%2Freact-native-aepmessaging.svg)](https://www.npmjs.com/package/@adobe/react-native-aepmessaging)
3
+ [![npm version](https://badge.fury.io/js/%40adobe%2Freact-native-aepmessaging.svg)](https://www.npmjs.com/package/@adobe/react-native-aepmessaging)
5
4
  [![npm downloads](https://img.shields.io/npm/dm/@adobe/react-native-aepmessaging)](https://www.npmjs.com/package/@adobe/react-native-aepmessaging)
6
5
 
7
- `@adobe/react-native-aepmessaging` is a wrapper around the iOS and Android [Adobe Journey Optimizer Messaging](https://aep-sdks.gitbook.io/docs/using-mobile-extensions/adobe-journey-optimizer) to allow for integration with React Native applications.
6
+ `@adobe/react-native-aepmessaging` is a wrapper around the iOS and Android [Adobe Journey Optimizer Messaging](https://developer.adobe.com/client-sdks/documentation/adobe-journey-optimizer) extension to allow for integration with React Native applications.
8
7
 
9
8
  ## Prerequisites
10
9
 
11
10
  The messaging extension has the following peer dependenices, which must be installed prior to installing the messaging extension:
11
+
12
12
  - [Core](../core/README.md)
13
13
  - [Edge](../edge/README.md)
14
14
  - [Edge Identity](../edgeidentity/README.md)
15
15
 
16
16
  ## Installation
17
17
 
18
- See [Requirements and Installation](https://github.com/adobe/aepsdk-react-native#requirements) instructions on the main page
18
+ See [Requirements and Installation](https://github.com/adobe/aepsdk-react-native#requirements) instructions on the main page
19
19
 
20
20
  Install the `@adobe/react-native-aepmessaging` package:
21
21
 
22
+ NPM:
23
+
22
24
  ```bash
23
- cd MyReactApp
24
25
  npm install @adobe/react-native-aepmessaging
25
26
  ```
26
27
 
28
+ Yarn:
29
+
30
+ ```bash
31
+ yarn add @adobe/react-native-aepmessaging
32
+ ```
33
+
27
34
  ## Usage
28
35
 
29
- ### [Messaging](https://aep-sdks.gitbook.io/docs/using-mobile-extensions/adobe-journey-optimizer)
36
+ ### [Messaging](https://developer.adobe.com/client-sdks/documentation/adobe-journey-optimizer)
30
37
 
31
38
  ### Installing and registering the extension with the AEP Mobile Core
32
39
 
33
- ### Initialization
34
- Initializing the SDK should be done in native code, additional documentation on how to initialize the SDK can be found [here](https://github.com/adobe/aepsdk-react-native#initializing).
40
+ ### Initialization
41
+
42
+ Initializing the SDK should be done in native code, additional documentation on how to initialize the SDK can be found [here](https://github.com/adobe/aepsdk-react-native#initializing).
43
+
44
+ Example:
35
45
 
36
- Example:
46
+ iOS
37
47
 
38
- iOS
39
48
  ```objectivec
40
49
  @import AEPCore;
41
50
  @import AEPLifecycle;
42
51
  @import AEPEdge;
43
52
  @import AEPEdgeIdentity;
44
53
  @import AEPMessaging;
54
+
45
55
  ...
46
56
  @implementation AppDelegate
47
57
  -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
48
58
  [AEPMobileCore setLogLevel: AEPLogLevelDebug];
49
59
  [AEPMobileCore configureWithAppId:@"yourAppID"];
50
- [AEPMobileCore registerExtensions: @[AEPMobileEdge.class, AEPMobileEdgeIdentity.class, AEPMobileMessaging.class] completion:^{
51
- [AEPMobileCore lifecycleStart:@{@"contextDataKey": @"contextDataVal"}];
52
- }
53
- ];
54
60
 
61
+ const UIApplicationState appState = application.applicationState;
62
+
63
+ [AEPMobileCore registerExtensions: @[AEPMobileEdgeIdentity.class, AEPMobileEdge.class, AEPMobileMessaging.class, AEPMobileOptimize.class] completion:^{
64
+ if (appState != UIApplicationStateBackground) {
65
+ [AEPMobileCore lifecycleStart:nil}];
66
+ }
67
+ }];
55
68
  return YES;
56
69
  }
57
70
 
58
71
  @end
59
72
  ```
60
73
 
61
- Android
74
+ Android
75
+
62
76
  ```java
63
77
  import com.adobe.marketing.mobile.AdobeCallback;
64
78
  import com.adobe.marketing.mobile.InvalidInitException;
@@ -66,9 +80,9 @@ import com.adobe.marketing.mobile.Lifecycle;
66
80
  import com.adobe.marketing.mobile.LoggingMode;
67
81
  import com.adobe.marketing.mobile.MobileCore;
68
82
  import com.adobe.marketing.mobile.Edge;
69
- import com.adobe.marketing.mobile.edge.identity;
83
+ import com.adobe.marketing.mobile.edge.identity.Identity;
70
84
  import com.adobe.marketing.mobile.Messaging;
71
-
85
+
72
86
  ...
73
87
  import android.app.Application;
74
88
  ...
@@ -80,55 +94,337 @@ public class MainApplication extends Application implements ReactApplication {
80
94
  ...
81
95
  MobileCore.setApplication(this);
82
96
  MobileCore.setLogLevel(LoggingMode.DEBUG);
83
- try {
84
- Edge.registerExtension();
85
- Identity.registerExtension();
86
- Messaging.registerExtension();
87
- MobileCore.configureWithAppID("yourAppID");
88
- MobileCore.start(new AdobeCallback() {
89
- @Override
90
- public void call(Object o) {
91
- MobileCore.lifecycleStart(null);
92
- }
93
- });
94
- } catch (InvalidInitException e) {
95
- ...
96
- }
97
+ MobileCore.configureWithAppID("yourAppID");
98
+ List<Class<? extends Extension>> extensions = Arrays.asList(
99
+ Edge.EXTENSION,
100
+ Identity.EXTENSION,
101
+ Messaging.EXTENSION,
102
+ Lifecycle.EXTENSION);
103
+ MobileCore.registerExtensions(extensions, o -> {
104
+ MobileCore.lifecycleStart(null);
105
+ });
97
106
  }
98
- }
107
+ }
99
108
  ```
100
109
 
101
110
  ### Importing the extension:
102
111
 
103
112
  ```javascript
104
- import {AEPMessaging} from '@adobe/react-native-aepmessaging';
113
+ import {
114
+ Messaging,
115
+ MessagingDelegate,
116
+ MessagingEdgeEventType,
117
+ Message,
118
+ } from "@adobe/react-native-aepmessaging";
105
119
  ```
106
120
 
107
121
  ## API reference
122
+
108
123
  ### extensionVersion
109
124
 
125
+ Returns the version of the AEPMessaging extension
126
+
110
127
  **Syntax**
128
+
111
129
  ```javascript
112
- extensionVersion(): Promise<string>;
130
+ extensionVersion(): Promise<string>
113
131
  ```
114
132
 
115
133
  **Example**
134
+
116
135
  ```javascript
117
- Messaging.extensionVersion().then(version => console.log("AdobeExperienceSDK: Messaging version: " + version));
136
+ Messaging.extensionVersion().then((version) =>
137
+ console.log("AdobeExperienceSDK: Messaging version: " + version)
138
+ );
118
139
  ```
119
140
 
120
- ## Configure Adobe Journey Optimizer
121
- To configure Adobe Journey optimizer Messaging in Launch follow steps in [Configure Adobe Journey optimizer](https://aep-sdks.gitbook.io/docs/using-mobile-extensions/adobe-journey-optimizer#setup-adobe-journey-optimizer-extension)
141
+ ## Configure Adobe Journey Optimizer
142
+
143
+ To configure Adobe Journey Optimizer Messaging in Launch follow the steps in [Configure Adobe Journey Optimizer](https://developer.adobe.com/client-sdks/documentation/adobe-journey-optimizer/#setup-adobe-journey-optimizer-extension)
122
144
 
123
145
  ## Push Notification Setup
124
- Handling push notifications must be done in native (Android/iOS) code for the React Native app. To configure push notification in the native project, follow the instructions provided by their respective platforms:
125
- - [Apple - iOS push notification setup](https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns)
146
+
147
+ Handling push notifications must be done in native (Android/iOS) code for the React Native app. To configure push notifications in the native project, follow the instructions provided for their respective platforms:
148
+
149
+ - [Apple - iOS push notification setup](https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns)
126
150
  - [Google - Android push notification setup](https://firebase.google.com/docs/cloud-messaging/android/client)
127
151
 
128
- ## Messaging SDK API usage
129
- Messaging SDK APIs must be called from the native Android/iOS project of React Native app.
152
+ ## Push Messaging APIs usage
153
+
154
+ The AEPMessaging extension's push messaging APIs must be called from the native Android/iOS project of React Native app.
155
+
156
+ ###### [iOS API usage](https://github.com/adobe/aepsdk-messaging-ios/blob/main/Documentation/sources/usage.md)
157
+
158
+ ##### [Android API usage](https://github.com/adobe/aepsdk-messaging-android/blob/main/Documentation/sources/api-usage.md)
159
+
160
+ In Android, [MessagingPushPayload](https://github.com/adobe/aepsdk-messaging-android/blob/main/Documentation/sources/messaging-push-payload.md#messagingpushpayload-usage) can be used for getting the notification attributes like title, body, and action. These are useful for push notification creation.
161
+
162
+ ## In-app messages API reference
163
+
164
+ ### refreshInAppMessages
165
+
166
+ Initiates a network call to retrieve remote in-app message definitions.
167
+
168
+ **Syntax**
169
+
170
+ ```javascript
171
+ refreshInAppMessages()
172
+ ```
173
+
174
+ **Example**
175
+
176
+ ```javascript
177
+ Messaging.refreshInAppMessages()
178
+ ```
179
+
180
+ ### setMessagingDelegate
181
+
182
+ Sets a custom `MessagingDelegate` in AEPCore to listen for Message lifecycle events.
183
+
184
+ **Syntax**
185
+
186
+ ```javascript
187
+ setMessagingDelegate(delegate: MessagingDelegate)
188
+ ```
189
+
190
+ **Example**
191
+
192
+ ```javascript
193
+ const messagingDelegate = {
194
+ onShow(message: Message) {
195
+ // Action after message is displayed.
196
+ },
197
+
198
+ onDismiss(message: Message) {
199
+ // Action after message is dismissed.
200
+ },
201
+
202
+ shouldShowMessage(message: Message) {
203
+ return true; //Return true to show the Message else return false
204
+ },
205
+
206
+ urlLoaded(url: string, message: Message) {
207
+ // Action after message loads an URL
208
+ },
209
+ };
210
+
211
+ Messaging.setMessagingDelegate(messagingDelegate)
212
+ ```
213
+
214
+ ### saveMessage
215
+
216
+ Natively caches the provided `Message` object in-memory. Cached `Message` objects can used at a later time to show the cached `Message` or perform other actions on the `Message` object. This function should be called from the `shouldShowMessage` function of the custom `MessagingDelegate`.
217
+
218
+ **Syntax**
219
+
220
+ ```javascript
221
+ saveMessage(message: Message)
222
+ ```
223
+
224
+ **Example**
225
+
226
+ ```javascript
227
+ const messagingDelegate = {
228
+
229
+ shouldShowMessage(message: Message) {
230
+ Messaging.saveMessage(message)
231
+ return false;
232
+ },
233
+
234
+ };
235
+ ```
236
+
237
+ ## Handling In App Messages using Message Object
238
+
239
+ The `Message` object passed to the `MessagingDelegate` contains the following functions to handle a message:
240
+
241
+ ### show
242
+
243
+ Signals to the `UIService` that the message should be shown.
244
+
245
+ **Syntax**
246
+
247
+ ```javascript
248
+ show()
249
+ ```
250
+
251
+ **Example**
252
+
253
+ ```javascript
254
+ var message: Message
255
+ message.show()
256
+ ```
257
+
258
+ ### dismiss
259
+
260
+ Signals to the `UIService` that the message should be dismissed.
261
+
262
+ **Syntax**
263
+
264
+ ```javascript
265
+ dismiss(((suppressAutoTrack: ?boolean) = false))
266
+ ```
267
+
268
+ **Example**
269
+
270
+ ```javascript
271
+ var message: Message
272
+ message.dismiss(true)
273
+ ```
274
+
275
+ ### track
276
+
277
+ Generates an Edge Event for the provided interaction and event type.
278
+
279
+ **Syntax**
280
+
281
+ ```javascript
282
+ track(interaction: ?string, eventType: MessagingEdgeEventType)
283
+ ```
284
+
285
+ **Example**
286
+
287
+ ```javascript
288
+ var message: Message;
289
+ message.track("sample text", MessagingEdgeEventType.IN_APP_DISMISS)
290
+ ```
291
+
292
+ ### handleJavascriptMessage
293
+
294
+ Adds a handler for Javascript messages sent from the message's webview.
295
+
296
+ **Syntax**
297
+
298
+ ```javascript
299
+ handleJavascriptMessage(name: string) : Promise<?any>
300
+ ```
301
+
302
+ **Example**
303
+
304
+ ```javascript
305
+ var message: Message;
306
+ message.handleJavascriptMessage("test").then((data) => {})
307
+ ```
308
+
309
+ ### setAutoTrack
310
+
311
+ Enables/Disables autotracking for message events.
312
+
313
+ **Syntax**
314
+
315
+ ```javascript
316
+ setAutoTrack(autoTrack: boolean)
317
+ ```
318
+
319
+ **Example**
320
+
321
+ ```javascript
322
+ var message: Message;
323
+ message.setAutoTrack(true)
324
+ ```
325
+
326
+ ### clear
327
+
328
+ Clears the reference to the in-memory cached `Message` object. This function must be called if a message was saved by calling `Messaging.saveMessage` but no longer needed. Failure to call this function leads to memory leaks.
329
+
330
+ **Syntax**
331
+
332
+ ```javascript
333
+ clear()
334
+ ```
335
+
336
+ **Example**
337
+
338
+ ```javascript
339
+ var message: Message
340
+ message.clear()
341
+ ```
342
+
343
+ ## Programatically control the display of in-app messages
344
+
345
+ App developers can now create a type `MessagingDelegate` in order to be alerted when specific events occur during the lifecycle of an in-app message.
346
+
347
+ Definition of type `MessagingDelegate` is:
348
+
349
+ ```javascript
350
+ type MessagingDelegate = {
351
+ onShow(message: Message): void,
352
+
353
+ onDismiss(message: Message): void,
354
+
355
+ shouldShowMessage(message: Message): boolean,
356
+
357
+ urlLoaded(url: string, message: Message): void,
358
+ };
359
+ ```
360
+
361
+ Objects of type `MessagingDelegate` can be created as shown below:
362
+
363
+ ```javascript
364
+ const messagingDelegate = {
365
+ onShow(message: Message) {
366
+ // Action after message is displayed.
367
+ },
368
+
369
+ onDismiss(message: Message) {
370
+ // Action after message is dismissed.
371
+ },
372
+
373
+ shouldShowMessage(message: Message) {
374
+ return true; //Return true to show the Message else return false
375
+ },
376
+
377
+ urlLoaded(url: string, message: Message) {
378
+ // Action after message loads an URL
379
+ },
380
+ };
381
+ ```
382
+
383
+ ### Controlling when the message should be shown to the end user.
384
+
385
+ If a `MessagingDelegate` has been set, the delegate's `shouldShowMessage` function will be called prior to displaying an in-app message for which the end user has qualified. The developer is responsible for returning true if the message should be shown, or false if the message should be suppressed.
386
+
387
+ Below is an example of when the developer may choose to suppress an in-app message due to the status of some other workflow within the app:
388
+
389
+ ```javascript
390
+ function shouldShowMessage(message: Message): boolean {
391
+ if (someOtherWorkflowStatus == "inProgress") {
392
+ return false;
393
+ }
394
+
395
+ return true;
396
+ }
397
+ ```
398
+
399
+ Another option for the developer is to store a reference to the `Message` object, and call the `show` function on it at a later time. To use this functionality, app developers can call `Messaging.saveMessage(message)` from the `shouldShowMessage` of the `MessagingDelegate` for caching the Message on the native side of the RN AEPMessaging package.
400
+ Continuing with the above example, the developer has stored the message that was triggered initially, and chooses to show it upon completion of the other workflow:
130
401
 
131
- ###### [iOS API usage](https://github.com/adobe/aepsdk-messaging-ios/blob/main/Documentation/APIUsage.md)
402
+ ```javascript
403
+ var cachedMessage: Message;
132
404
 
133
- ##### [Android API usage](https://github.com/adobe/aepsdk-messaging-android/blob/main/Documentation/APIUsage.md)
134
- In Android, [MessagingPushPayload](https://github.com/adobe/aepsdk-messaging-android/blob/main/Documentation/push/MessagingPushPayload.md#messagingpushpayload-usage) can be used for getting the notification attributes like title, body, and action. These are useful for push notification creation.
405
+ function otherWorkflowFinished() {
406
+ anotherWorkflowStatus = "complete";
407
+ cachedMessage.show();
408
+ }
409
+
410
+ function shouldShowMessage(message: Message): boolean {
411
+ if (anotherWorkflowStatus === "inProgress") {
412
+ // store the current message for later use
413
+ Messaging.saveMessage(message);
414
+ cachedMessage = message;
415
+ return false;
416
+ }
417
+
418
+ return true;
419
+ }
420
+ ```
421
+
422
+ **Important:** If the cached message is no longer needed after being used, free up the references to the `Message` object by calling `message.clearMessage()` to prevent memory leaks. In above example after displaying the in app message using cached message object if it is no longer needed then it should be cleared as shown below.
423
+
424
+ ```javascript
425
+ function otherWorkflowFinished() {
426
+ anotherWorkflowStatus = "complete";
427
+ currentMessage.show();
428
+ currentMessage.clearMessage();
429
+ }
430
+ ```
@@ -11,13 +11,16 @@ buildscript {
11
11
 
12
12
  apply plugin: 'com.android.library'
13
13
 
14
+ def safeExtGet(prop, fallback) {
15
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
16
+ }
17
+
14
18
  android {
15
- compileSdkVersion 29
16
- // buildToolsVersion "23.0.1"
19
+ compileSdkVersion safeExtGet('compileSdkVersion', 33)
17
20
 
18
21
  defaultConfig {
19
- minSdkVersion 19
20
- targetSdkVersion 29
22
+ minSdkVersion safeExtGet('minSdkVersion', 19)
23
+ targetSdkVersion safeExtGet('targetSdkVersion', 33)
21
24
  versionCode 1
22
25
  versionName "1.0"
23
26
  }
@@ -32,6 +35,6 @@ repositories {
32
35
  }
33
36
 
34
37
  dependencies {
38
+ api "com.adobe.marketing.mobile:messaging:[2.1.0, 3.0["
35
39
  implementation "com.facebook.react:react-native:+"
36
- api "com.adobe.marketing.mobile:messaging:1.+"
37
40
  }