Skip to content

Commit e669cd0

Browse files
committed
feat: SQDSDKS-7454 Add events api support
- Added RoktEventManager to facilitate events from RoktSDK. - Updated sample app to demonstrate Rokt event subscriptions and handling. - Refactored placement selection methods for better clarity and usability. - Improved TypeScript definitions to include RoktEventManager.
1 parent 6d54154 commit e669cd0

File tree

8 files changed

+118
-35
lines changed

8 files changed

+118
-35
lines changed

ios/RNMParticle.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
/* Begin PBXBuildFile section */
1010
DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */; };
1111
DBDF24DD1E007EB1000F3D73 /* RNMParticle.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */; };
12+
DBDF24DE1E007EB1000F3D74 /* RoktEventManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DD1E007EB1000F3D74 /* RoktEventManager.m */; };
13+
DBDF24DF1E007EB1000F3D74 /* RoktEventManager.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DC1E007EB1000F3D74 /* RoktEventManager.h */; };
14+
DBDF24E01E007EB1000F3D75 /* RNMPRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = DBDF24DE1E007EB1000F3D75 /* RNMPRokt.m */; };
15+
DBDF24E11E007EB1000F3D75 /* RNMPRokt.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DBDF24DD1E007EB1000F3D75 /* RNMPRokt.h */; };
1216
/* End PBXBuildFile section */
1317

1418
/* Begin PBXCopyFilesBuildPhase section */
@@ -28,6 +32,10 @@
2832
DBDF24D71E007EB1000F3D73 /* libRNMParticle.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMParticle.a; sourceTree = BUILT_PRODUCTS_DIR; };
2933
DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMParticle.h; sourceTree = "<group>"; };
3034
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMParticle.m; sourceTree = "<group>"; };
35+
DBDF24DC1E007EB1000F3D74 /* RoktEventManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoktEventManager.h; sourceTree = "<group>"; };
36+
DBDF24DD1E007EB1000F3D74 /* RoktEventManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoktEventManager.m; sourceTree = "<group>"; };
37+
DBDF24DD1E007EB1000F3D75 /* RNMPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMPRokt.h; sourceTree = "<group>"; };
38+
DBDF24DE1E007EB1000F3D75 /* RNMPRokt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMPRokt.m; sourceTree = "<group>"; };
3139
/* End PBXFileReference section */
3240

3341
/* Begin PBXFrameworksBuildPhase section */
@@ -62,6 +70,10 @@
6270
children = (
6371
DBDF24DA1E007EB1000F3D73 /* RNMParticle.h */,
6472
DBDF24DB1E007EB1000F3D73 /* RNMParticle.m */,
73+
DBDF24DC1E007EB1000F3D74 /* RoktEventManager.h */,
74+
DBDF24DD1E007EB1000F3D74 /* RoktEventManager.m */,
75+
DBDF24DD1E007EB1000F3D75 /* RNMPRokt.h */,
76+
DBDF24DE1E007EB1000F3D75 /* RNMPRokt.m */,
6577
);
6678
path = RNMParticle;
6779
sourceTree = "<group>";
@@ -124,6 +136,8 @@
124136
buildActionMask = 2147483647;
125137
files = (
126138
DBDF24DC1E007EB1000F3D73 /* RNMParticle.m in Sources */,
139+
DBDF24DE1E007EB1000F3D74 /* RoktEventManager.m in Sources */,
140+
DBDF24E01E007EB1000F3D75 /* RNMPRokt.m in Sources */,
127141
);
128142
runOnlyForDeploymentPostprocessing = 0;
129143
};

ios/RNMParticle/RNMPRokt.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ + (void)load {
7777

7878
[self subscribeViewEvents:identifer];
7979

80-
// TODO: Add placeholders and fontFilesMap
8180
[[[MParticle sharedInstance] rokt] selectPlacements:identifer
8281
attributes:finalAttributes
8382
embeddedViews:nativePlaceholders

js/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
CacheConfig,
55
IRoktConfig,
66
ColorMode,
7+
RoktEventManager,
78
} from './rokt/rokt';
89
import RoktLayoutView, { RoktLayoutViewProps } from './rokt/rokt-layout-view';
910

@@ -326,7 +327,7 @@ export declare class MParticleError {
326327
}
327328

328329
// Export Rokt functionality
329-
export { Rokt, RoktConfigBuilder, CacheConfig, IRoktConfig, ColorMode, RoktLayoutView, RoktLayoutViewProps };
330+
export { Rokt, RoktConfigBuilder, RoktEventManager, CacheConfig, IRoktConfig, ColorMode, RoktLayoutView, RoktLayoutViewProps };
330331

331332
// Default export
332333
declare const _default: {

js/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { NativeModules } from 'react-native'
44
import {
55
Rokt,
66
RoktConfigBuilder,
7-
CacheConfig
7+
CacheConfig,
8+
RoktEventManager
89
} from './rokt/rokt'
910
import RoktLayoutView from './rokt/rokt-layout-view'
1011

@@ -681,6 +682,7 @@ const MParticle = {
681682
Rokt,
682683
RoktConfigBuilder,
683684
CacheConfig,
685+
RoktEventManager,
684686
RoktLayoutView,
685687

686688
upload, // Methods
@@ -705,3 +707,6 @@ const MParticle = {
705707
}
706708

707709
export default MParticle
710+
711+
// Expose RoktEventManager utilities as named exports for convenience
712+
export { RoktEventManager }

js/rokt/rokt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ export class RoktConfigBuilder implements Partial<IRoktConfig> {
7070
}
7171
}
7272

73+
const { RoktEventManager } = NativeModules;
74+
75+
export { RoktEventManager };
76+
7377
export type ColorMode = "light" | "dark" | "system";

sample/__mocks__/react-native-mparticle.js

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable */
21
/**
32
* Mock for react-native-mparticle
43
* This mock provides a simple API that mimics the essential functionality
@@ -9,11 +8,11 @@ class User {
98
constructor(userId) {
109
this.userId = userId;
1110
}
12-
11+
1312
getMpid() {
1413
return this.userId;
1514
}
16-
15+
1716
setUserAttribute() {}
1817
getUserAttributes(callback) {
1918
callback({ testAttribute: 'testValue' });
@@ -37,12 +36,12 @@ class IdentityRequest {
3736
this.email = email;
3837
return this;
3938
}
40-
39+
4140
setCustomerID(customerId) {
4241
this.customerId = customerId;
4342
return this;
4443
}
45-
44+
4645
setUserIdentity(userIdentity, identityType) {
4746
this[identityType] = userIdentity;
4847
return this;
@@ -54,23 +53,23 @@ class Identity {
5453
var currentUser = new User('mockUserId123');
5554
completion(currentUser);
5655
}
57-
56+
5857
static login(request, completion) {
5958
completion(null, 'mockUserId123', 'mockPreviousUserId456');
6059
}
61-
60+
6261
static logout(request, completion) {
6362
completion(null, 'mockUserId123');
6463
}
65-
64+
6665
static identify(request, completion) {
6766
completion(null, 'mockUserId123', 'mockPreviousUserId456');
6867
}
69-
68+
7069
static modify(request, completion) {
7170
completion(null, 'mockUserId123', 'mockPreviousUserId456');
7271
}
73-
72+
7473
static aliasUsers(request, completion) {
7574
completion(true, null);
7675
}
@@ -102,17 +101,17 @@ class AliasRequest {
102101
this.sourceMpid = mpid;
103102
return this;
104103
}
105-
104+
106105
destinationMpid(mpid) {
107106
this.destinationMpid = mpid;
108107
return this;
109108
}
110-
109+
111110
startTime(time) {
112111
this.startTime = time;
113112
return this;
114113
}
115-
114+
116115
endTime(time) {
117116
this.endTime = time;
118117
return this;
@@ -121,9 +120,26 @@ class AliasRequest {
121120

122121
// Mock Rokt
123122
const Rokt = {
124-
selectPlacements: () => Promise.resolve()
123+
selectPlacements: () => Promise.resolve(),
125124
};
126125

126+
// Rokt mocks
127+
class RoktConfigBuilder {
128+
withColorMode(mode) {
129+
return this;
130+
}
131+
132+
build() {
133+
return {};
134+
}
135+
}
136+
137+
// Simple passthrough React component placeholder
138+
const RoktLayoutView = () => null;
139+
140+
// Event manager stub (can be used with NativeEventEmitter)
141+
const RoktEventManager = {};
142+
127143
// Constants
128144
const EventType = {
129145
Navigation: 1,
@@ -134,20 +150,20 @@ const EventType = {
134150
UserPreference: 6,
135151
Social: 7,
136152
Other: 8,
137-
Media: 9
153+
Media: 9,
138154
};
139155

140156
const UserIdentityType = {
141157
Email: 7,
142158
CustomerId: 1,
143-
Alias: 8
159+
Alias: 8,
144160
};
145161

146162
const ProductActionType = {
147163
AddToCart: 1,
148164
RemoveFromCart: 2,
149165
Checkout: 3,
150-
Purchase: 7
166+
Purchase: 7,
151167
};
152168

153169
// Main mock object
@@ -160,13 +176,15 @@ const MParticle = {
160176
TransactionAttributes,
161177
CommerceEvent,
162178
AliasRequest,
179+
RoktConfigBuilder,
180+
RoktLayoutView,
163181
Rokt,
164-
182+
165183
// Constants
166184
EventType,
167185
UserIdentityType,
168186
ProductActionType,
169-
187+
170188
// Methods
171189
logEvent: () => {},
172190
logCommerceEvent: () => {},
@@ -178,7 +196,8 @@ const MParticle = {
178196
getAttributions: (callback) => callback({ attributionResults: 'mock results' }),
179197
upload: () => {},
180198
setUploadInterval: () => {},
181-
setLocation: () => {}
199+
setLocation: () => {},
182200
};
183201

184-
module.exports = MParticle;
202+
module.exports = MParticle;
203+
module.exports.RoktEventManager = RoktEventManager;

sample/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ["module:@react-native/babel-preset"],
2+
presets: ['module:@react-native/babel-preset'],
33
};

sample/index.js

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66

77
import React, { Component } from 'react';
88
import {
9-
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View,
13-
Button,
14-
Platform, findNodeHandle, ScrollView
9+
AppRegistry,
10+
StyleSheet,
11+
Text,
12+
View,
13+
Button,
14+
Platform, findNodeHandle, ScrollView, NativeEventEmitter,
1515
} from 'react-native';
16-
import MParticle from 'react-native-mparticle';
16+
import MParticle, {RoktEventManager} from 'react-native-mparticle';
1717

1818
const { RoktConfigBuilder, RoktLayoutView } = MParticle;
1919

20+
const eventManagerEmitter = new NativeEventEmitter(RoktEventManager);
21+
2022
export default class MParticleSample extends Component {
2123
constructor(props) {
2224
super(props);
@@ -123,6 +125,31 @@ export default class MParticleSample extends Component {
123125

124126
componentDidMount() {
125127
MParticle.getSession(session => this.setState({ session }))
128+
if (eventManagerEmitter) {
129+
// Save subscriptions so we can remove them later
130+
this.roktCallbackListener = eventManagerEmitter.addListener(
131+
'RoktCallback',
132+
data => {
133+
console.log('roktCallback received: ' + data.callbackValue);
134+
},
135+
);
136+
137+
this.roktEventsListener = eventManagerEmitter.addListener('RoktEvents', data => {
138+
console.log(`*** ROKT EVENT *** ${JSON.stringify(data)}`);
139+
});
140+
} else {
141+
console.warn('RoktEventManager not available, skipping event listeners');
142+
}
143+
}
144+
145+
componentWillUnmount() {
146+
// Remove event listeners to avoid duplicate subscriptions
147+
if (this.roktCallbackListener) {
148+
this.roktCallbackListener.remove();
149+
}
150+
if (this.roktEventsListener) {
151+
this.roktEventsListener.remove();
152+
}
126153
}
127154

128155
_toggleOptOut() {
@@ -158,7 +185,19 @@ export default class MParticleSample extends Component {
158185
})
159186
}
160187

161-
_roktSelectPlacements() {
188+
_roktSelectOverlayPlacements() {
189+
this._roktSelectPlacements('MSDKOverlayLayout')
190+
}
191+
192+
_roktSelectBottomSheetPlacements() {
193+
this._roktSelectPlacements('MSDKBottomSheetLayout')
194+
}
195+
196+
_roktSelectEmbeddedPlacements() {
197+
this._roktSelectPlacements('MSDKEmbeddedLayout')
198+
}
199+
200+
_roktSelectPlacements(identifier) {
162201
// Platform-specific attributes
163202
const iosAttributes = {
164203
"email": "[email protected]",
@@ -183,7 +222,7 @@ export default class MParticleSample extends Component {
183222
const placeholderMap = {
184223
'Location1': findNodeHandle(this.placeholder1.current),
185224
}
186-
MParticle.Rokt.selectPlacements('MSDKEmbeddedLayout', attributes, placeholderMap, config, null).then((result) => {
225+
MParticle.Rokt.selectPlacements(identifier, attributes, placeholderMap, config, null).then((result) => {
187226
console.debug("Rokt selectPlacements result: " + JSON.stringify(result))
188227
}).catch((error) => {
189228
console.debug("Rokt selectPlacements error: " + JSON.stringify(error))
@@ -233,7 +272,9 @@ export default class MParticleSample extends Component {
233272
onPress={() => {this._incrementAttribute()}}
234273
title="Increment Attribute"/>
235274
<Text style={styles.instructions}>ROKT</Text>
236-
<Button title="ROKT Test" onPress={() => {this._roktSelectPlacements()}}/>
275+
<Button title="ROKT Embedded" onPress={() => {this._roktSelectEmbeddedPlacements()}}/>
276+
<Button title="ROKT Overlay" onPress={() => {this._roktSelectOverlayPlacements()}}/>
277+
<Button title="ROKT BottomSheet" onPress={() => {this._roktSelectBottomSheetPlacements()}}/>
237278
<RoktLayoutView
238279
ref={this.placeholder1}
239280
placeholderName="Location1" />

0 commit comments

Comments
 (0)