diff --git a/apps/AEPSampleAppNewArchEnabled/app/MessagingView.tsx b/apps/AEPSampleAppNewArchEnabled/app/MessagingView.tsx index 270d5adbf..4d82cdc9d 100644 --- a/apps/AEPSampleAppNewArchEnabled/app/MessagingView.tsx +++ b/apps/AEPSampleAppNewArchEnabled/app/MessagingView.tsx @@ -13,13 +13,24 @@ governing permissions and limitations under the License. import React from 'react'; import {Button, Text, View, ScrollView} from 'react-native'; import {MobileCore} from '@adobe/react-native-aepcore'; -import {Messaging, PersonalizationSchema} from '@adobe/react-native-aepmessaging' +import { + Messaging, + PersonalizationSchema, + MessagingEdgeEventType, + PropositionItem, + Message, + ContentCard, + HTMLProposition, + JSONPropositionItem +} from '@adobe/react-native-aepmessaging' +import { MessagingProposition } from '@adobe/react-native-aepmessaging'; import styles from '../styles/styles'; import { useRouter } from 'expo-router'; const SURFACES = ['android-cbe-preview', 'cbe/json', 'android-cc']; const SURFACES_WITH_CONTENT_CARDS = ['android-cc']; + const messagingExtensionVersion = async () => { const version = await Messaging.extensionVersion(); console.log(`AdobeExperienceSDK: Messaging version: ${version}`); @@ -33,21 +44,24 @@ const refreshInAppMessages = () => { const setMessagingDelegate = () => { Messaging.setMessagingDelegate({ onDismiss: msg => console.log('dismissed!', msg), - onShow: msg => console.log('show', msg), + onShow: msg => { + console.log('show', msg); + msg.handleJavascriptMessage('myInappCallback', (content: string) => { + console.log('Received webview content in onShow:', content); + }); + }, shouldShowMessage: () => true, shouldSaveMessage: () => true, urlLoaded: (url, message) => console.log(url, message), }); console.log('messaging delegate set'); }; - const getPropositionsForSurfaces = async () => { const messages = await Messaging.getPropositionsForSurfaces(SURFACES); - console.log(JSON.stringify(messages)); + console.log('getPropositionsForSurfaces', JSON.stringify(messages)); }; - const trackAction = async () => { - MobileCore.trackAction('tuesday', {full: true}); + MobileCore.trackAction('iamjs', {full: true}); }; const updatePropositionsForSurfaces = async () => { @@ -75,7 +89,8 @@ const trackContentCardInteraction = async () => { for (const proposition of propositions) { for (const propositionItem of proposition.items) { if (propositionItem.schema === PersonalizationSchema.CONTENT_CARD) { - Messaging.trackContentCardInteraction(proposition, propositionItem); + // Cast to ContentCard for the legacy tracking method + Messaging.trackContentCardInteraction(proposition, propositionItem as any); console.log('trackContentCardInteraction', proposition, propositionItem); } } @@ -93,7 +108,8 @@ const trackContentCardDisplay = async () => { for (const proposition of propositions) { for (const propositionItem of proposition.items) { if (propositionItem.schema === PersonalizationSchema.CONTENT_CARD) { - Messaging.trackContentCardDisplay(proposition, propositionItem); + // Cast to ContentCard for the legacy tracking method + Messaging.trackContentCardDisplay(proposition, propositionItem as any); console.log('trackContentCardDisplay', proposition, propositionItem); } } @@ -101,6 +117,26 @@ const trackContentCardDisplay = async () => { } } + +// Method demonstrating unified tracking using PropositionItem methods +const unifiedTrackingExample = async () => { + const messages = await Messaging.getPropositionsForSurfaces(SURFACES); + for (const surface of SURFACES) { + const propositions = messages[surface] || []; + + for (const proposition of propositions) { + const propositionWrapper = new MessagingProposition(proposition); + if (propositionWrapper.items.length > 0) { + const propositionItem = propositionWrapper.items[0]; + propositionItem.track(MessagingEdgeEventType.DISPLAY); + propositionItem.track('content_card_clicked', MessagingEdgeEventType.INTERACT, null); + } + } + } +} + + + function MessagingView() { const router = useRouter(); @@ -125,6 +161,7 @@ function MessagingView() {