Skip to content

Commit 8a9fd83

Browse files
authored
feat: Add support for Get / Set SessionId on Rokt (#45)
1 parent 8ccc2a6 commit 8a9fd83

4 files changed

Lines changed: 98 additions & 3 deletions

File tree

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
.upToNextMajor(from: "8.0.0")),
1818
.package(name: "Rokt-Widget",
1919
url: "https://github.com/ROKT/rokt-sdk-ios",
20-
.upToNextMajor(from: "4.10.0")),
20+
.upToNextMajor(from: "4.15.0")),
2121
],
2222
targets: [
2323
.target(

mParticle-Rokt.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ Pod::Spec.new do |s|
2121
objc.source_files = 'mParticle-Rokt/*.{h,m}'
2222
objc.public_header_files = 'mParticle-Rokt/*.h'
2323
objc.dependency 'mParticle-Apple-SDK', '~> 8.0'
24-
objc.dependency 'Rokt-Widget', '~> 4.10'
24+
objc.dependency 'Rokt-Widget', '~> 4.15'
2525
end
2626

2727
# Swift subspec
2828
s.subspec 'Swift' do |swift|
2929
swift.source_files = 'mParticle-Rokt-Swift/*.swift'
3030
swift.dependency 'mParticle-Rokt/ObjC'
3131
swift.dependency 'mParticle-Apple-SDK', '~> 8.0'
32-
swift.dependency 'Rokt-Widget', '~> 4.10'
32+
swift.dependency 'Rokt-Widget', '~> 4.15'
3333
end
3434

3535
# Default includes both

mParticle-Rokt/MPKitRokt.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,23 @@ - (MPKitExecStatus *)close {
511511
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
512512
}
513513

514+
/// Set the session id to use for the next execute call.
515+
/// This is useful for cases where you have a session id from a non-native integration,
516+
/// e.g. WebView, and you want the session to be consistent across integrations.
517+
///
518+
/// @param sessionId The session id to be set. Must be a non-empty string.
519+
- (MPKitExecStatus *)setSessionId:(NSString *)sessionId {
520+
[Rokt setSessionIdWithSessionId:sessionId];
521+
return [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
522+
}
523+
524+
/// Get the session id to use within a non-native integration e.g. WebView.
525+
///
526+
/// @return The session id or nil if no session is present.
527+
- (NSString *)getSessionId {
528+
return [Rokt getSessionId];
529+
}
530+
514531
#pragma mark - User attributes and identities
515532

516533
- (MPKitExecStatus *)setUserIdentity:(NSString *)identityString identityType:(MPUserIdentity)identityType {

mParticle_RoktTests/mParticle_RoktTests.m

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ - (MPKitExecStatus *)purchaseFinalized:(NSString *)placementId
2121
catalogItemId:(NSString *)catalogItemId
2222
success:(NSNumber *)success;
2323

24+
- (MPKitExecStatus *)setSessionId:(NSString *)sessionId;
25+
- (NSString *)getSessionId;
26+
2427
- (NSDictionary<NSString *, RoktEmbeddedView *> * _Nullable) confirmEmbeddedViews:(NSDictionary<NSString *, MPRoktEmbeddedView *> * _Nullable)embeddedViews;
2528

2629
+ (void)addIdentityAttributes:(NSMutableDictionary<NSString *, NSString *> * _Nullable)attributes filteredUser:(FilteredMParticleUser * _Nonnull)filteredUser;
@@ -796,4 +799,79 @@ - (void)testExecuteWithIdentifierLogsSelectPlacementEventWithPreparedAttributes
796799
[mockMParticleInstance stopMocking];
797800
}
798801

802+
#pragma mark - setSessionId tests
803+
804+
- (void)testSetSessionIdCallsRoktSDK {
805+
id mockRoktSDK = OCMClassMock([Rokt class]);
806+
807+
NSString *sessionId = @"test-session-id-12345";
808+
809+
// Expect Rokt setSessionIdWithSessionId call with correct parameter
810+
OCMExpect([mockRoktSDK setSessionIdWithSessionId:sessionId]);
811+
812+
// Execute the method
813+
MPKitExecStatus *status = [self.kitInstance setSessionId:sessionId];
814+
815+
// Verify
816+
XCTAssertNotNil(status);
817+
XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess);
818+
XCTAssertEqualObjects(status.integrationId, @181);
819+
OCMVerifyAll(mockRoktSDK);
820+
821+
[mockRoktSDK stopMocking];
822+
}
823+
824+
- (void)testSetSessionIdWithEmptyString {
825+
id mockRoktSDK = OCMClassMock([Rokt class]);
826+
827+
NSString *sessionId = @"";
828+
829+
// Expect Rokt setSessionIdWithSessionId call - the kit passes it through, Rokt SDK handles validation
830+
OCMExpect([mockRoktSDK setSessionIdWithSessionId:sessionId]);
831+
832+
// Execute the method
833+
MPKitExecStatus *status = [self.kitInstance setSessionId:sessionId];
834+
835+
// Verify
836+
XCTAssertNotNil(status);
837+
XCTAssertEqual(status.returnCode, MPKitReturnCodeSuccess);
838+
OCMVerifyAll(mockRoktSDK);
839+
840+
[mockRoktSDK stopMocking];
841+
}
842+
843+
#pragma mark - getSessionId tests
844+
845+
- (void)testGetSessionIdReturnsSessionIdFromRoktSDK {
846+
id mockRoktSDK = OCMClassMock([Rokt class]);
847+
848+
NSString *expectedSessionId = @"mock-session-id-67890";
849+
850+
// Stub Rokt getSessionId to return the expected session ID
851+
OCMStub([mockRoktSDK getSessionId]).andReturn(expectedSessionId);
852+
853+
// Execute the method
854+
NSString *result = [self.kitInstance getSessionId];
855+
856+
// Verify
857+
XCTAssertEqualObjects(result, expectedSessionId, @"Should return the session id from the Rokt SDK");
858+
859+
[mockRoktSDK stopMocking];
860+
}
861+
862+
- (void)testGetSessionIdReturnsNilWhenRoktSDKReturnsNil {
863+
id mockRoktSDK = OCMClassMock([Rokt class]);
864+
865+
// Stub Rokt getSessionId to return nil
866+
OCMStub([mockRoktSDK getSessionId]).andReturn(nil);
867+
868+
// Execute the method
869+
NSString *result = [self.kitInstance getSessionId];
870+
871+
// Verify
872+
XCTAssertNil(result, @"Should return nil when Rokt SDK returns nil");
873+
874+
[mockRoktSDK stopMocking];
875+
}
876+
799877
@end

0 commit comments

Comments
 (0)