@digia-engage/core 1.0.0-beta.5 → 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.
Files changed (44) hide show
  1. package/DigiaEngageReactNative.podspec +12 -15
  2. package/README.md +8 -17
  3. package/android/.project +28 -0
  4. package/android/build.gradle +1 -1
  5. package/android/settings.gradle +1 -2
  6. package/android/src/main/java/com/digia/engage/rn/DigiaModule.kt +1 -1
  7. package/android/src/main/java/com/digia/engage/rn/DigiaSlotViewManager.kt +146 -31
  8. package/ios/DigiaEngageModule.m +1 -0
  9. package/ios/DigiaHostViewManager.swift +41 -17
  10. package/ios/DigiaModule.swift +55 -6
  11. package/ios/DigiaSlotViewManager.swift +190 -22
  12. package/ios/RNEventBridgePlugin.swift +10 -11
  13. package/lib/commonjs/Digia.js +50 -0
  14. package/lib/commonjs/Digia.js.map +1 -1
  15. package/lib/commonjs/DigiaHostView.js +4 -50
  16. package/lib/commonjs/DigiaHostView.js.map +1 -1
  17. package/lib/commonjs/DigiaSlotView.js +35 -53
  18. package/lib/commonjs/DigiaSlotView.js.map +1 -1
  19. package/lib/commonjs/NativeDigiaEngage.js.map +1 -1
  20. package/lib/module/Digia.js +50 -0
  21. package/lib/module/Digia.js.map +1 -1
  22. package/lib/module/DigiaHostView.js +4 -51
  23. package/lib/module/DigiaHostView.js.map +1 -1
  24. package/lib/module/DigiaSlotView.js +35 -51
  25. package/lib/module/DigiaSlotView.js.map +1 -1
  26. package/lib/module/NativeDigiaEngage.js.map +1 -1
  27. package/lib/typescript/Digia.d.ts +12 -0
  28. package/lib/typescript/Digia.d.ts.map +1 -1
  29. package/lib/typescript/DigiaHostView.d.ts +2 -29
  30. package/lib/typescript/DigiaHostView.d.ts.map +1 -1
  31. package/lib/typescript/DigiaSlotView.d.ts +3 -40
  32. package/lib/typescript/DigiaSlotView.d.ts.map +1 -1
  33. package/lib/typescript/NativeDigiaEngage.d.ts.map +1 -1
  34. package/lib/typescript/index.d.ts +1 -1
  35. package/lib/typescript/index.d.ts.map +1 -1
  36. package/lib/typescript/types.d.ts +21 -0
  37. package/lib/typescript/types.d.ts.map +1 -1
  38. package/package.json +8 -18
  39. package/src/Digia.ts +60 -1
  40. package/src/DigiaHostView.tsx +5 -48
  41. package/src/DigiaSlotView.tsx +40 -48
  42. package/src/NativeDigiaEngage.ts +1 -0
  43. package/src/index.ts +1 -1
  44. package/src/types.ts +30 -0
package/src/Digia.ts CHANGED
@@ -15,14 +15,25 @@
15
15
  * ```
16
16
  */
17
17
 
18
+ import { DeviceEventEmitter } from 'react-native';
18
19
  import { nativeDigiaModule } from './NativeDigiaEngage';
19
- import type { DigiaConfig, DigiaDelegate, DigiaPlugin, InAppPayload } from './types';
20
+ import type {
21
+ DigiaConfig,
22
+ DigiaDelegate,
23
+ DigiaExperienceEvent,
24
+ DigiaPlugin,
25
+ InAppPayload,
26
+ } from './types';
20
27
 
21
28
  class DigiaClass implements DigiaDelegate {
22
29
  private readonly _plugins = new Map<string, DigiaPlugin>();
23
30
  // Tracks whether the native bridge plugin (RNEventBridgePlugin) has been
24
31
  // wired to the native SDK. Done once on the first Digia.register() call.
25
32
  private _nativeBridgeWired = false;
33
+ // Cache of triggered payloads keyed by campaign ID, used to reconstruct
34
+ // the full InAppPayload when overlay lifecycle events arrive from native.
35
+ private readonly _activePayloads = new Map<string, InAppPayload>();
36
+ private _engageSubscription: { remove(): void } | null = null;
26
37
 
27
38
  /**
28
39
  * Initialise the Digia Engage SDK.
@@ -59,6 +70,7 @@ class DigiaClass implements DigiaDelegate {
59
70
  // so the delegate is ready when JS campaigns start flowing.
60
71
  if (!this._nativeBridgeWired) {
61
72
  nativeDigiaModule.registerBridge();
73
+ this._startEngageListener();
62
74
  this._nativeBridgeWired = true;
63
75
  }
64
76
  plugin.setup(this);
@@ -87,18 +99,65 @@ class DigiaClass implements DigiaDelegate {
87
99
  this._plugins.forEach((plugin) => plugin.forwardScreen(name));
88
100
  }
89
101
 
102
+
90
103
  // ── DigiaDelegate ────────────────────────────────────────────────────────
91
104
  // Mirrors DigiaCEPDelegate on Android.
92
105
  // Forwards to the native DigiaCEPDelegate via the bridge.
93
106
 
94
107
  onCampaignTriggered(payload: InAppPayload): void {
108
+ this._activePayloads.set(payload.id, payload);
95
109
  nativeDigiaModule.triggerCampaign(payload.id, payload.content, payload.cepContext);
96
110
  }
97
111
 
98
112
  onCampaignInvalidated(campaignId: string): void {
113
+ this._activePayloads.delete(campaignId);
99
114
  nativeDigiaModule.invalidateCampaign(campaignId);
100
115
  }
101
116
 
117
+ // ── Overlay event forwarding ─────────────────────────────────────────────
118
+
119
+ /**
120
+ * Subscribes to `digiaOverlayEvent` emitted by the native
121
+ * RNEventBridgePlugin when the Compose overlay fires a lifecycle event
122
+ * (impressed / clicked / dismissed).
123
+ *
124
+ * Each event is forwarded to every registered plugin's notifyEvent() so
125
+ * that CEP plugins (e.g. WebEngagePlugin) can report analytics.
126
+ */
127
+ private _startEngageListener(): void {
128
+ if (this._engageSubscription) return;
129
+ this._engageSubscription = DeviceEventEmitter.addListener(
130
+ 'digiaEngageEvent',
131
+ (data: { campaignId: string; type: string; elementId?: string }) =>
132
+ this._forwardExperienceEvent(data),
133
+ );
134
+ }
135
+
136
+ private _forwardExperienceEvent(
137
+ data: { campaignId: string; type: string; elementId?: string },
138
+ ): void {
139
+ const payload = this._activePayloads.get(data.campaignId);
140
+ if (!payload) return;
141
+
142
+ let event: DigiaExperienceEvent;
143
+ switch (data.type) {
144
+ case 'impressed':
145
+ event = { type: 'impressed' };
146
+ break;
147
+ case 'clicked':
148
+ event = { type: 'clicked', elementId: data.elementId };
149
+ break;
150
+ case 'dismissed':
151
+ event = { type: 'dismissed' };
152
+ this._activePayloads.delete(data.campaignId);
153
+ break;
154
+ default:
155
+ return;
156
+ }
157
+
158
+ this._plugins.forEach((plugin) => plugin.notifyEvent(event, payload));
159
+ }
160
+
102
161
  }
103
162
 
104
163
  export const Digia = new DigiaClass();
@@ -1,35 +1,8 @@
1
1
  /**
2
2
  * DigiaHostView
3
3
  *
4
- * A transparent React Native view that attaches the Digia Android Compose
5
- * overlay layer (dialogs, bottom sheets) on top of your app's content.
6
- *
7
- * ─── Usage ───────────────────────────────────────────────────────────────────
8
- * Place `<DigiaHostView>` at the **root** of your component tree so that
9
- * Digia dialogs and bottom sheets can stack on top of all your content.
10
- *
11
- * ```tsx
12
- * import React from 'react';
13
- * import { StyleSheet, View } from 'react-native';
14
- * import { DigiaHostView } from '@digia/engage-react-native';
15
- *
16
- * export default function App() {
17
- * return (
18
- * <View style={styles.root}>
19
- * <DigiaHostView style={StyleSheet.absoluteFill} />
20
- * {/ * your navigation / app content here * /}
21
- * </View>
22
- * );
23
- * }
24
- *
25
- * const styles = StyleSheet.create({ root: { flex: 1 } });
26
- * ```
27
- *
28
- * On Android this mounts a Jetpack Compose `DigiaHost` composable that
29
- * manages dialog + bottom-sheet presentation triggered by CEP plugins.
30
- * On iOS this mounts a SwiftUI `DigiaHost` via UIHostingController that
31
- * manages the same overlay layer above React Native content.
32
- * ─────────────────────────────────────────────────────────────────────────────
4
+ * Transparent full-screen overlay that hosts Digia dialogs and bottom sheets.
5
+ * Place at the root of your component tree so overlays stack above all content.
33
6
  */
34
7
 
35
8
  import React from 'react';
@@ -45,41 +18,25 @@ interface DigiaHostViewProps {
45
18
  style?: StyleProp<ViewStyle>;
46
19
  }
47
20
 
48
- // requireNativeComponent expects a plain ViewStyle, not StyleProp.
49
21
  interface NativeDigiaHostViewProps {
50
22
  style?: ViewStyle;
23
+ pointerEvents?: 'auto' | 'none' | 'box-none' | 'box-only';
51
24
  }
52
25
 
53
- // Fabric (New Architecture) resolves view configs lazily — no UIManager
54
- // guard needed. requireNativeComponent is called unconditionally on iOS and Android.
55
26
  const NativeDigiaHostView =
56
27
  Platform.OS === 'android' || Platform.OS === 'ios'
57
28
  ? requireNativeComponent<NativeDigiaHostViewProps>('DigiaHostView')
58
29
  : null;
59
30
 
60
- // ── DigiaHostView ─────────────────────────────────────────────────────────────
61
-
62
31
  export function DigiaHostView({ style }: DigiaHostViewProps) {
63
32
  if ((Platform.OS === 'android' || Platform.OS === 'ios') && NativeDigiaHostView) {
64
- // The native DigiaHost (Compose on Android, SwiftUI on iOS) renders
65
- // dialogs / bottom sheets that float above the view hierarchy on their
66
- // own — the host view only needs to be mounted in the tree, not take up
67
- // any screen space.
68
33
  return (
69
34
  <NativeDigiaHostView
70
- style={StyleSheet.flatten([styles.host, style])}
35
+ pointerEvents="none"
36
+ style={StyleSheet.flatten([StyleSheet.absoluteFillObject, style])}
71
37
  />
72
38
  );
73
39
  }
74
40
 
75
- // Other platforms: no-op.
76
41
  return null;
77
42
  }
78
-
79
- const styles = StyleSheet.create({
80
- host: {
81
- width: 0,
82
- height: 0,
83
- overflow: 'hidden',
84
- },
85
- });
@@ -1,80 +1,72 @@
1
1
  /**
2
2
  * DigiaSlotView
3
3
  *
4
- * A React Native view that renders inline campaign content (banners, cards,
5
- * widgets) at a specific placement position inside your screen layout.
6
- *
7
- * On Android this mounts a Jetpack Compose `DigiaSlot` composable that
8
- * observes the slot payload for the given placement key and renders the
9
- * matching campaign component. On iOS this mounts the equivalent SwiftUI
10
- * `DigiaSlot` view via UIHostingController.
11
- *
12
- * ─── Usage ───────────────────────────────────────────────────────────────────
13
- * ```tsx
14
- * import { DigiaSlotView } from '@digia/engage-react-native';
15
- *
16
- * // Fixed height (you control the space)
17
- * <DigiaSlotView
18
- * placementKey="hero_banner"
19
- * style={{ width: '100%', height: 200 }}
20
- * />
21
- *
22
- * // Inside a scroll view
23
- * <ScrollView>
24
- * <ProductList />
25
- * <DigiaSlotView
26
- * placementKey="pdp_mid_banner"
27
- * style={{ width: '100%', height: 120 }}
28
- * />
29
- * <RelatedProducts />
30
- * </ScrollView>
31
- * ```
32
- *
33
- * The `placementKey` must match the key the marketer selects when creating
34
- * inline content on the Digia dashboard. The view collapses to nothing when
35
- * no campaign is active for that key.
36
- *
37
- * ─── Sizing ──────────────────────────────────────────────────────────────────
38
- * React Native's layout system controls the dimensions of this view.
39
- * Provide an explicit `height` (or flex) via the `style` prop so that the
40
- * native Compose layer has space to render. When no campaign is active the
41
- * Compose `DigiaSlot` renders nothing inside that space.
42
- * ─────────────────────────────────────────────────────────────────────────────
4
+ * Renders inline campaign content at a placement position.
5
+ * Auto-sizes to match native content height via `onContentSizeChange`;
6
+ * pass an explicit `height` in `style` to fix the size instead.
43
7
  */
44
8
 
45
- import React from 'react';
9
+ import React, { useCallback, useState } from 'react';
46
10
  import {
47
11
  Platform,
12
+ StyleSheet,
48
13
  requireNativeComponent,
49
14
  type StyleProp,
50
15
  type ViewStyle,
51
16
  } from 'react-native';
52
17
 
53
18
  interface DigiaSlotViewProps {
54
- /** Placement key that links this view to a Digia dashboard slot. */
55
19
  placementKey: string;
56
20
  style?: StyleProp<ViewStyle>;
57
21
  }
58
22
 
59
- // Fabric (New Architecture) resolves view configs lazily — no UIManager
60
- // guard needed. requireNativeComponent is called unconditionally on iOS and Android.
23
+ interface NativeDigiaSlotViewProps extends DigiaSlotViewProps {
24
+ onContentSizeChange?: (event: { nativeEvent: { height: number } }) => void;
25
+ collapsable?: boolean;
26
+ }
27
+
61
28
  const NativeDigiaSlotView =
62
29
  Platform.OS === 'android' || Platform.OS === 'ios'
63
- ? requireNativeComponent<DigiaSlotViewProps>('DigiaSlotView')
30
+ ? requireNativeComponent<NativeDigiaSlotViewProps>('DigiaSlotView')
64
31
  : null;
65
32
 
66
- // ── DigiaSlotView ─────────────────────────────────────────────────────────────
67
-
68
33
  export function DigiaSlotView({ placementKey, style }: DigiaSlotViewProps) {
34
+ const [contentHeight, setContentHeight] = useState(0);
35
+
36
+ const onContentSizeChange = useCallback(
37
+ (event: { nativeEvent: { height: number } }) => {
38
+ const h = event.nativeEvent.height ?? 0;
39
+ setContentHeight(Math.max(0, h));
40
+ },
41
+ [],
42
+ );
43
+
69
44
  if ((Platform.OS === 'android' || Platform.OS === 'ios') && NativeDigiaSlotView) {
45
+ const flatStyle = StyleSheet.flatten(style) || {};
46
+ const hasExplicitHeight = flatStyle.height !== undefined;
47
+
48
+ if (hasExplicitHeight) {
49
+ return (
50
+ <NativeDigiaSlotView
51
+ placementKey={placementKey}
52
+ style={[{ width: '100%' }, style]}
53
+ {...(Platform.OS === 'android' ? { collapsable: false } : {})}
54
+ />
55
+ );
56
+ }
57
+
58
+ // 1dp bootstrap ensures a real layout pass before any campaign arrives.
59
+ const bootstrapHeight = Math.max(contentHeight, 1);
60
+
70
61
  return (
71
62
  <NativeDigiaSlotView
72
63
  placementKey={placementKey}
73
- style={style}
64
+ style={[{ width: '100%', height: bootstrapHeight }, style]}
65
+ onContentSizeChange={onContentSizeChange}
66
+ {...(Platform.OS === 'android' ? { collapsable: false } : {})}
74
67
  />
75
68
  );
76
69
  }
77
70
 
78
- // Other platforms: not yet implemented — render nothing.
79
71
  return null;
80
72
  }
@@ -50,6 +50,7 @@ export interface Spec extends TurboModule {
50
50
 
51
51
  /** Invalidate / dismiss a campaign by its ID. */
52
52
  invalidateCampaign(campaignId: string): void;
53
+
53
54
  }
54
55
 
55
56
  // Try TurboModuleRegistry first (New Architecture / JSI).
package/src/index.ts CHANGED
@@ -12,4 +12,4 @@
12
12
  export { Digia } from './Digia';
13
13
  export { DigiaHostView } from './DigiaHostView';
14
14
  export { DigiaSlotView } from './DigiaSlotView';
15
- export type { DigiaConfig, DigiaDelegate, DigiaPlugin, InAppPayload } from './types';
15
+ export type { DigiaConfig, DigiaDelegate, DigiaExperienceEvent, DigiaPlugin, InAppPayload } from './types';
package/src/types.ts CHANGED
@@ -12,6 +12,30 @@ export interface InAppPayload {
12
12
  cepContext: Record<string, unknown>;
13
13
  }
14
14
 
15
+ // ─── Experience events ────────────────────────────────────────────────────────
16
+
17
+ /** The experience became visible to the user. */
18
+ export interface ExperienceImpressed {
19
+ readonly type: 'impressed';
20
+ }
21
+
22
+ /** The user interacted with an actionable element. */
23
+ export interface ExperienceClicked {
24
+ readonly type: 'clicked';
25
+ readonly elementId?: string;
26
+ }
27
+
28
+ /** The experience was dismissed — by the user or programmatically. */
29
+ export interface ExperienceDismissed {
30
+ readonly type: 'dismissed';
31
+ }
32
+
33
+ /** Discriminated union of all experience event types. */
34
+ export type DigiaExperienceEvent =
35
+ | ExperienceImpressed
36
+ | ExperienceClicked
37
+ | ExperienceDismissed;
38
+
15
39
  /**
16
40
  * Delegate passed by the Digia SDK to each registered plugin via setup().
17
41
  *
@@ -35,6 +59,12 @@ export interface DigiaPlugin {
35
59
  readonly identifier: string;
36
60
  /** Called by Digia.register() — do not call manually. */
37
61
  setup(delegate: DigiaDelegate): void;
62
+ /**
63
+ * Called by the Digia SDK when the overlay fires a lifecycle event
64
+ * (impressed / clicked / dismissed). Plugins use this to report
65
+ * analytics back to their CEP platform.
66
+ */
67
+ notifyEvent(event: DigiaExperienceEvent, payload: InAppPayload): void;
38
68
  /** Called by Digia.setCurrentScreen() — do not call manually. */
39
69
  forwardScreen(name: string): void;
40
70
  /** Called by Digia.unregister() or when tearing down the app. */