@adobe/react-native-aepmessaging 7.1.1 → 7.2.1
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/README.md +61 -2
- package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingConstants.java +19 -0
- package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingModule.java +152 -18
- package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingUtil.java +1 -1
- package/dist/Messaging.d.ts +17 -0
- package/dist/Messaging.js +34 -7
- package/dist/Messaging.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/models/ContentCard.d.ts +6 -1
- package/dist/models/ContentCard.js +9 -0
- package/dist/models/ContentCard.js.map +1 -1
- package/dist/models/HTMLProposition.d.ts +6 -2
- package/dist/models/HTMLProposition.js +9 -0
- package/dist/models/HTMLProposition.js.map +1 -1
- package/dist/models/JSONProposition.d.ts +12 -0
- package/dist/models/{JSONPropositionItem.js → JSONProposition.js} +10 -1
- package/dist/models/JSONProposition.js.map +1 -0
- package/dist/models/Message.d.ts +14 -0
- package/dist/models/Message.js +51 -1
- package/dist/models/Message.js.map +1 -1
- package/dist/models/MessagingProposition.d.ts +10 -3
- package/dist/models/MessagingProposition.js +45 -0
- package/dist/models/MessagingProposition.js.map +1 -1
- package/dist/models/MessagingPropositionItem.d.ts +3 -2
- package/dist/models/PropositionItem.d.ts +83 -0
- package/dist/models/PropositionItem.js +78 -0
- package/dist/models/PropositionItem.js.map +1 -0
- package/ios/src/RCTAEPMessaging.mm +32 -0
- package/ios/src/RCTAEPMessaging.swift +150 -45
- package/ios/src/RCTAEPMessagingConstants.swift +5 -1
- package/ios/src/RCTAEPMessagingDataBridge.swift +19 -0
- package/package.json +2 -2
- package/src/Messaging.ts +46 -13
- package/src/index.ts +13 -5
- package/src/models/ContentCard.ts +12 -1
- package/src/models/HTMLProposition.ts +15 -6
- package/src/models/{JSONPropositionItem.ts → JSONProposition.ts} +15 -6
- package/src/models/Message.ts +61 -2
- package/src/models/MessagingProposition.ts +45 -3
- package/src/models/MessagingPropositionItem.ts +6 -2
- package/src/models/PropositionItem.ts +135 -0
- package/tutorials/In-App Messaging.md +67 -0
- package/dist/models/JSONPropositionItem.d.ts +0 -8
- package/dist/models/JSONPropositionItem.js.map +0 -1
|
@@ -10,12 +10,54 @@
|
|
|
10
10
|
language governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { MessagingPropositionItem } from './MessagingPropositionItem';
|
|
14
13
|
import { ScopeDetails } from './ScopeDetails';
|
|
14
|
+
import { PersonalizationSchema } from './PersonalizationSchema';
|
|
15
|
+
import { ContentCard } from './ContentCard';
|
|
16
|
+
import { HTMLProposition } from './HTMLProposition';
|
|
17
|
+
import { JSONPropositionItem } from './JSONProposition';
|
|
18
|
+
import { PropositionItem } from './PropositionItem';
|
|
15
19
|
|
|
16
|
-
export
|
|
20
|
+
export class MessageProposition {
|
|
17
21
|
id: string;
|
|
18
22
|
scope: string;
|
|
19
23
|
scopeDetails: ScopeDetails;
|
|
20
|
-
items:
|
|
24
|
+
items: PropositionItem[];
|
|
25
|
+
|
|
26
|
+
constructor(raw: { id: string; scope: string; scopeDetails: ScopeDetails; items?: any[] }) {
|
|
27
|
+
this.id = raw?.id ?? '';
|
|
28
|
+
this.scope = raw?.scope ?? '';
|
|
29
|
+
this.scopeDetails = (raw?.scopeDetails as ScopeDetails) ?? ({} as ScopeDetails);
|
|
30
|
+
|
|
31
|
+
// Mirror activity.id into activity.activityID for convenience
|
|
32
|
+
const activityIdFromScope = this.scopeDetails?.activity?.id ?? '';
|
|
33
|
+
if (this.scopeDetails?.activity) {
|
|
34
|
+
(this.scopeDetails.activity as any).activityID = activityIdFromScope;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const rawItems = Array.isArray(raw?.items) ? raw.items : [];
|
|
38
|
+
this.items = rawItems.map((itemData: any) => {
|
|
39
|
+
const activityId = this.scopeDetails?.activity?.id ?? '';
|
|
40
|
+
let instance: any;
|
|
41
|
+
switch (itemData?.schema) {
|
|
42
|
+
case PersonalizationSchema.CONTENT_CARD:
|
|
43
|
+
instance = new ContentCard(itemData as any);
|
|
44
|
+
(instance as any).activityID = activityId;
|
|
45
|
+
return instance;
|
|
46
|
+
case PersonalizationSchema.HTML_CONTENT:
|
|
47
|
+
instance = new HTMLProposition(itemData as any);
|
|
48
|
+
(instance as any).activityID = activityId;
|
|
49
|
+
return instance;
|
|
50
|
+
case PersonalizationSchema.JSON_CONTENT:
|
|
51
|
+
instance = new JSONPropositionItem(itemData as any);
|
|
52
|
+
(instance as any).activityID = activityId;
|
|
53
|
+
return instance;
|
|
54
|
+
default:
|
|
55
|
+
instance = new PropositionItem(itemData as any);
|
|
56
|
+
(instance as any).activityID = activityId;
|
|
57
|
+
return instance;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
21
61
|
}
|
|
62
|
+
|
|
63
|
+
export { MessageProposition as MessagingProposition };
|
|
@@ -12,11 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
import { ContentCard } from './ContentCard';
|
|
14
14
|
import { HTMLProposition } from './HTMLProposition';
|
|
15
|
-
import { JSONPropositionItem } from './
|
|
15
|
+
import { JSONPropositionItem } from './JSONProposition';
|
|
16
16
|
import { InAppMessage } from './InAppMessage';
|
|
17
|
+
import { PropositionItem } from './PropositionItem';
|
|
17
18
|
|
|
19
|
+
// Union type for all possible proposition item types
|
|
20
|
+
// All items now extend PropositionItem and have unified tracking capabilities
|
|
18
21
|
export type MessagingPropositionItem =
|
|
19
22
|
| ContentCard
|
|
20
23
|
| HTMLProposition
|
|
21
24
|
| InAppMessage
|
|
22
|
-
| JSONPropositionItem
|
|
25
|
+
| JSONPropositionItem
|
|
26
|
+
| PropositionItem;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the
|
|
4
|
+
"License"); you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
|
|
7
|
+
or agreed to in writing, software distributed under the License is
|
|
8
|
+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF
|
|
9
|
+
ANY KIND, either express or implied. See the License for the specific
|
|
10
|
+
language governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { NativeModules } from 'react-native';
|
|
14
|
+
import { PersonalizationSchema } from './PersonalizationSchema';
|
|
15
|
+
import MessagingEdgeEventType from './MessagingEdgeEventType';
|
|
16
|
+
|
|
17
|
+
const RCTAEPMessaging = NativeModules.AEPMessaging;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Base PropositionItem interface that all proposition items implement
|
|
21
|
+
*/
|
|
22
|
+
export interface PropositionItemData {
|
|
23
|
+
id: string;
|
|
24
|
+
uuid: string;
|
|
25
|
+
schema: PersonalizationSchema;
|
|
26
|
+
activityID: string;
|
|
27
|
+
data: {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A PropositionItem represents a personalization JSON object returned by Konductor.
|
|
34
|
+
* This is the base class that provides tracking functionality for all proposition items
|
|
35
|
+
* including ContentCards, InApp messages, and code-based experiences.
|
|
36
|
+
*
|
|
37
|
+
* This mirrors the native Android PropositionItem class functionality.
|
|
38
|
+
*/
|
|
39
|
+
export class PropositionItem {
|
|
40
|
+
id: string;
|
|
41
|
+
uuid: string;
|
|
42
|
+
activityID: string;
|
|
43
|
+
schema: PersonalizationSchema;
|
|
44
|
+
data: { [key: string]: any };
|
|
45
|
+
|
|
46
|
+
constructor(propositionItemData: PropositionItemData) {
|
|
47
|
+
this.id = propositionItemData.id;
|
|
48
|
+
this.schema = propositionItemData.schema;
|
|
49
|
+
this.data = propositionItemData.data;
|
|
50
|
+
this.uuid = propositionItemData.uuid;
|
|
51
|
+
this.activityID = propositionItemData.activityID;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Gets the PropositionItem identifier.
|
|
56
|
+
*
|
|
57
|
+
* @returns {string} The PropositionItem identifier
|
|
58
|
+
*/
|
|
59
|
+
getItemId(): string {
|
|
60
|
+
return this.id;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Gets the PropositionItem content schema.
|
|
65
|
+
*
|
|
66
|
+
* @returns {PersonalizationSchema} The PropositionItem content schema
|
|
67
|
+
*/
|
|
68
|
+
getSchema(): PersonalizationSchema {
|
|
69
|
+
return this.schema;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets the PropositionItem data.
|
|
74
|
+
*
|
|
75
|
+
* @returns {object} The PropositionItem data
|
|
76
|
+
*/
|
|
77
|
+
getItemData(): { [key: string]: any } {
|
|
78
|
+
return this.data;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Tracks interaction with this proposition item.
|
|
83
|
+
* This is the core tracking method that all proposition items use.
|
|
84
|
+
*
|
|
85
|
+
* @param {MessagingEdgeEventType} eventType - The MessagingEdgeEventType specifying event type for the interaction
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* propositionItem.track(MessagingEdgeEventType.DISPLAY);
|
|
89
|
+
*/
|
|
90
|
+
track(eventType: MessagingEdgeEventType): void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Tracks interaction with this proposition item.
|
|
94
|
+
*
|
|
95
|
+
* @param {string | null} interaction - String describing the interaction
|
|
96
|
+
* @param {MessagingEdgeEventType} eventType - The MessagingEdgeEventType specifying event type for the interaction
|
|
97
|
+
* @param {string[] | null} tokens - Array containing the sub-item tokens for recording interaction
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* // Track display
|
|
101
|
+
* propositionItem.track(null, MessagingEdgeEventType.DISPLAY, null);
|
|
102
|
+
*
|
|
103
|
+
* // Track interaction
|
|
104
|
+
* propositionItem.track("button_clicked", MessagingEdgeEventType.INTERACT, null);
|
|
105
|
+
*
|
|
106
|
+
* // Track with tokens
|
|
107
|
+
* propositionItem.track("click", MessagingEdgeEventType.INTERACT, ["token1", "token2"]);
|
|
108
|
+
*/
|
|
109
|
+
track(interaction: string | null, eventType: MessagingEdgeEventType, tokens: string[] | null): void;
|
|
110
|
+
|
|
111
|
+
// Implementation
|
|
112
|
+
track(
|
|
113
|
+
interactionOrEventType: string | null | MessagingEdgeEventType,
|
|
114
|
+
eventType?: MessagingEdgeEventType,
|
|
115
|
+
tokens?: string[] | null
|
|
116
|
+
): void {
|
|
117
|
+
// Handle overloaded method signatures
|
|
118
|
+
if (typeof interactionOrEventType === 'number' && eventType === undefined) {
|
|
119
|
+
// First overload: track(eventType)
|
|
120
|
+
this.trackWithDetails(null, interactionOrEventType, null);
|
|
121
|
+
} else if (typeof interactionOrEventType === 'string' || interactionOrEventType === null) {
|
|
122
|
+
// Second overload: track(interaction, eventType, tokens)
|
|
123
|
+
this.trackWithDetails(interactionOrEventType, eventType!, tokens || null);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Internal method that performs the actual tracking
|
|
129
|
+
*/
|
|
130
|
+
private trackWithDetails(interaction: string | null, eventType: MessagingEdgeEventType, tokens: string[] | null): void {
|
|
131
|
+
const nativeIdentifier = this.activityID ?? null;
|
|
132
|
+
RCTAEPMessaging.trackPropositionItem(nativeIdentifier, interaction, eventType, tokens);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Native handling of JavaScript events
|
|
2
|
+
|
|
3
|
+
You can handle events from in-app message interactions natively within your application by completing the following steps:
|
|
4
|
+
- [Implement and assign a `Messaging Delegate`](#implement-and-assign-a-messaging-delegate)
|
|
5
|
+
- [Register a JavaScript handler for your In-App Message](#register-a-javascript-handler-for-your-in-app-message)
|
|
6
|
+
- [Post the JavaScript message from your In-App Message](#post-the-javascript-message-from-your-in-app-message)
|
|
7
|
+
|
|
8
|
+
## Implement and assign a `Messaging Delegate`
|
|
9
|
+
|
|
10
|
+
To register a JavaScript event handler with a Message object, you will first need to implement and set a MessagingDelegate.
|
|
11
|
+
Please read the [documentation](../README.md/#programmatically-control-the-display-of-in-app-messages) for more detailed instructions on implementing and using a MessagingDelegate.
|
|
12
|
+
|
|
13
|
+
## Register a JavaScript handler for your In-App Message
|
|
14
|
+
|
|
15
|
+
In the `onShow` function of `MessagingDelegate`, call `handleJavascriptMessage(handlerName: string, handler: (content: string) => void)` to register your handler.
|
|
16
|
+
|
|
17
|
+
The name of the message you intend to pass from the JavaScript side should be specified in the first parameter.
|
|
18
|
+
|
|
19
|
+
### Example
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
Messaging.setMessagingDelegate({
|
|
23
|
+
onShow: msg => {
|
|
24
|
+
console.log('show', msg);
|
|
25
|
+
msg.handleJavascriptMessage(
|
|
26
|
+
'myInappCallback',
|
|
27
|
+
(content) => {
|
|
28
|
+
console.log('Received webview content:', content);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Post the JavaScript message from your In-App Message
|
|
36
|
+
|
|
37
|
+
Now that the in-app message has been displayed, the final step is to post the JavaScript message.
|
|
38
|
+
|
|
39
|
+
Continuing from the previous example, the developer is going to post the `myInappCallback` message from their HTML, which will in turn call the handler previously configured:
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<html>
|
|
43
|
+
<head>
|
|
44
|
+
<script type="text/javascript">
|
|
45
|
+
function callNative(action) {
|
|
46
|
+
try {
|
|
47
|
+
// the name of the message handler is the same name that must be registered in react native code.
|
|
48
|
+
// in this case the message name is "myInappCallback"
|
|
49
|
+
webkit.messageHandlers.myInappCallback.postMessage(action);
|
|
50
|
+
} catch(err) {
|
|
51
|
+
console.log('The native context does not exist yet'); }
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
</head>
|
|
55
|
+
<body>
|
|
56
|
+
<button onclick="callNative('callbacks are cool!')">Native callback!</button>
|
|
57
|
+
</body>
|
|
58
|
+
</html>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Note: (The above HTML is not representative of a valid in-app message, and is intended only to demonstrate how to post the JavaScript message).
|
|
62
|
+
|
|
63
|
+
When the user clicks the button inside of this in-app message, the handler configured in the previous step will be called. The handler will send an Experience Event tracking the interaction, and print the following message to the console:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
JavaScript body passed to react native callback: callbacks are cool!
|
|
67
|
+
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JSONPropositionItem.js","sourceRoot":"","sources":["../../src/models/JSONPropositionItem.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE"}
|