Skip to content

Commit

Permalink
feat: Add Privacy Manifest and Tracking Domain Logic (#249)
Browse files Browse the repository at this point in the history
* feat: Add Privacy Manifes
* feat: Setup Logic for Tracking URL (#248)
  • Loading branch information
BrandonStalnaker authored and einsteinx2 committed Feb 22, 2024
1 parent 5ae49fe commit 7e9c17d
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 15 deletions.
84 changes: 84 additions & 0 deletions PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyTrackingDomains</key>
<array/>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeCrashData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeAdvertisingData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeProductInteraction</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeDeviceID</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeUserID</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
</array>
</dict>
</array>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
</array>
</dict>
</plist>
60 changes: 47 additions & 13 deletions UnitTests/MPNetworkCommunicationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -838,30 +838,64 @@ - (void)testMaxAgeForCacheCapitalization {
XCTAssertEqualObjects([networkCommunication maxAgeForCache:test5], @16);
}

- (void)testPodURLRouting {
- (void)testPodURLRoutingAndTrackingURL {
// NOTE: All keys are fake and randomly generated just for this test
NSArray *testKeys = @[
@[@"4u8wmsug0pf5tbf58lgjiouma3qukrgbu", @"nativesdks.us1.mparticle.com", @"identity.us1.mparticle.com"],
@[@"us1-1vc4gbp24cdtx6e31s58icnymzy83f1uf", @"nativesdks.us1.mparticle.com", @"identity.us1.mparticle.com"],
@[@"us2-v2p8lr3w2g90vtpaumbq21zy05cl50qm3", @"nativesdks.us2.mparticle.com", @"identity.us2.mparticle.com"],
@[@"eu1-bkabfno0b8zpv5bwi2zm2mfa1kfml19al", @"nativesdks.eu1.mparticle.com", @"identity.eu1.mparticle.com"],
@[@"au1-iermuj83dbeoshm0n32f10feotclq6i4a", @"nativesdks.au1.mparticle.com", @"identity.au1.mparticle.com"],
@[@"st1-k77ivhkbbqf4ce0s3y12zpcthyn1ixfyu", @"nativesdks.st1.mparticle.com", @"identity.st1.mparticle.com"],
@[@"us3-w1y2y8yj8q58d5bx9u2dvtxzl4cpa7cuf", @"nativesdks.us3.mparticle.com", @"identity.us3.mparticle.com"]
@[@"4u8wmsug0pf5tbf58lgjiouma3qukrgbu", @"nativesdks.us1.mparticle.com", @"identity.us1.mparticle.com", @"tracking-nativesdks.us1.mparticle.com", @"tracking-identity.us1.mparticle.com"],
@[@"us1-1vc4gbp24cdtx6e31s58icnymzy83f1uf", @"nativesdks.us1.mparticle.com", @"identity.us1.mparticle.com", @"tracking-nativesdks.us1.mparticle.com", @"tracking-identity.us1.mparticle.com"],
@[@"us2-v2p8lr3w2g90vtpaumbq21zy05cl50qm3", @"nativesdks.us2.mparticle.com", @"identity.us2.mparticle.com", @"tracking-nativesdks.us2.mparticle.com", @"tracking-identity.us2.mparticle.com"],
@[@"eu1-bkabfno0b8zpv5bwi2zm2mfa1kfml19al", @"nativesdks.eu1.mparticle.com", @"identity.eu1.mparticle.com", @"tracking-nativesdks.eu1.mparticle.com", @"tracking-identity.eu1.mparticle.com"],
@[@"au1-iermuj83dbeoshm0n32f10feotclq6i4a", @"nativesdks.au1.mparticle.com", @"identity.au1.mparticle.com", @"tracking-nativesdks.au1.mparticle.com", @"tracking-identity.au1.mparticle.com"],
@[@"st1-k77ivhkbbqf4ce0s3y12zpcthyn1ixfyu", @"nativesdks.st1.mparticle.com", @"identity.st1.mparticle.com", @"tracking-nativesdks.st1.mparticle.com", @"tracking-identity.st1.mparticle.com"],
@[@"us3-w1y2y8yj8q58d5bx9u2dvtxzl4cpa7cuf", @"nativesdks.us3.mparticle.com", @"identity.us3.mparticle.com", @"tracking-nativesdks.us3.mparticle.com", @"tracking-identity.us3.mparticle.com"]
];
MPNetworkCommunication *networkCommunication = [[MPNetworkCommunication alloc] init];
MPStateMachine *stateMachine = [MParticle sharedInstance].stateMachine;
NSString *oldEventHost = @"nativesdks.mparticle.com";
NSString *oldIdentityHost = @"identity.mparticle.com";

MPNetworkCommunication *networkCommunication = [[MPNetworkCommunication alloc] init];
stateMachine.enableDirectRouting = NO;
stateMachine.attAuthorizationStatus = @(MPATTAuthorizationStatusNotDetermined);
for (NSArray *test in testKeys) {
NSString *key = test[0];
stateMachine.apiKey = key;

XCTAssertEqualObjects(oldEventHost, [networkCommunication defaultEventHost]);
XCTAssertEqualObjects(oldIdentityHost, [networkCommunication defaultIdentityHost]);
}

NSString *newEventHost = @"tracking-nativesdks.mparticle.com";
NSString *newIdentityHost = @"tracking-identity.mparticle.com";
stateMachine.attAuthorizationStatus = @(MPATTAuthorizationStatusAuthorized);
for (NSArray *test in testKeys) {
NSString *key = test[0];
stateMachine.apiKey = key;

XCTAssertEqualObjects(newEventHost, [networkCommunication defaultEventHost]);
XCTAssertEqualObjects(newIdentityHost, [networkCommunication defaultIdentityHost]);
}

stateMachine.enableDirectRouting = YES;
stateMachine.attAuthorizationStatus = @(MPATTAuthorizationStatusNotDetermined);
for (NSArray *test in testKeys) {
NSString *key = test[0];
stateMachine.apiKey = key;
NSString *eventHost = test[1];
NSString *identityHost = test[2];

XCTAssertEqualObjects(eventHost, [networkCommunication defaultHostWithSubdomain:kMPURLHostEventSubdomain apiKey:key enableDirectRouting:YES]);
XCTAssertEqualObjects(identityHost, [networkCommunication defaultHostWithSubdomain:kMPURLHostIdentitySubdomain apiKey:key enableDirectRouting:YES]);
XCTAssertEqualObjects(oldEventHost, [networkCommunication defaultHostWithSubdomain:kMPURLHostEventSubdomain apiKey:key enableDirectRouting:NO]);
XCTAssertEqualObjects(oldIdentityHost, [networkCommunication defaultHostWithSubdomain:kMPURLHostIdentitySubdomain apiKey:key enableDirectRouting:NO]);
XCTAssertEqualObjects(eventHost, [networkCommunication defaultEventHost]);
XCTAssertEqualObjects(identityHost, [networkCommunication defaultIdentityHost]);
}

stateMachine.attAuthorizationStatus = @(MPATTAuthorizationStatusAuthorized);
for (NSArray *test in testKeys) {
NSString *key = test[0];
stateMachine.apiKey = key;
NSString *eventHost = test[3];
NSString *identityHost = test[4];

XCTAssertEqualObjects(eventHost, [networkCommunication defaultEventHost]);
XCTAssertEqualObjects(identityHost, [networkCommunication defaultIdentityHost]);
}
}

Expand Down
2 changes: 2 additions & 0 deletions mParticle-Apple-SDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@
53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPIHasher.swift; sourceTree = "<group>"; };
D3724C182AE02AF60074CD67 /* mParticle_Apple_SDK_NoLocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mParticle_Apple_SDK_NoLocation.h; sourceTree = "<group>"; };
D3B3E2062AE028EC001AB58C /* mParticle_Apple_SDK.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mParticle_Apple_SDK.h; sourceTree = "<group>"; };
D3BA75152B614E3D008C3C65 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -852,6 +853,7 @@
53A79A6F29CCCD6400E7489F = {
isa = PBXGroup;
children = (
D3BA75152B614E3D008C3C65 /* PrivacyInfo.xcprivacy */,
53A79CFE29CE12AB00E7489F /* mParticle-Apple-SDK.modulemap */,
53A79CFF29CE23D600E7489F /* mParticle-Apple-SDK-NoLocation.modulemap */,
53A79A7B29CCCD6400E7489F /* mParticle-Apple-SDK */,
Expand Down
14 changes: 12 additions & 2 deletions mParticle-Apple-SDK/Network/MPNetworkCommunication.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
NSString *const kMPURLHostConfig = @"config2.mparticle.com";
NSString *const kMPURLHostEventSubdomain = @"nativesdks";
NSString *const kMPURLHostIdentitySubdomain = @"identity";
NSString *const kMPURLHostEventTrackingSubdomain = @"tracking-nativesdks";
NSString *const kMPURLHostIdentityTrackingSubdomain = @"tracking-identity";

NSString *const kMPIdentityCachingMaxAgeHeader = @"X-MP-Max-Age";

Expand Down Expand Up @@ -134,12 +136,20 @@ - (NSString *)defaultHostWithSubdomain:(NSString *)subdomain apiKey:(NSString *)

- (NSString *)defaultEventHost {
MPStateMachine *stateMachine = [MParticle sharedInstance].stateMachine;
return [self defaultHostWithSubdomain:kMPURLHostEventSubdomain apiKey:stateMachine.apiKey enableDirectRouting:stateMachine.enableDirectRouting];
if (stateMachine.attAuthorizationStatus.integerValue == MPATTAuthorizationStatusAuthorized) {
return [self defaultHostWithSubdomain:kMPURLHostEventTrackingSubdomain apiKey:stateMachine.apiKey enableDirectRouting:stateMachine.enableDirectRouting];
} else {
return [self defaultHostWithSubdomain:kMPURLHostEventSubdomain apiKey:stateMachine.apiKey enableDirectRouting:stateMachine.enableDirectRouting];
}
}

- (NSString *)defaultIdentityHost {
MPStateMachine *stateMachine = [MParticle sharedInstance].stateMachine;
return [self defaultHostWithSubdomain:kMPURLHostIdentitySubdomain apiKey:stateMachine.apiKey enableDirectRouting:stateMachine.enableDirectRouting];
if (stateMachine.attAuthorizationStatus.integerValue == MPATTAuthorizationStatusAuthorized) {
return [self defaultHostWithSubdomain:kMPURLHostIdentityTrackingSubdomain apiKey:stateMachine.apiKey enableDirectRouting:stateMachine.enableDirectRouting];
} else {
return [self defaultHostWithSubdomain:kMPURLHostIdentitySubdomain apiKey:stateMachine.apiKey enableDirectRouting:stateMachine.enableDirectRouting];
}
}

- (MPURL *)configURL {
Expand Down

0 comments on commit 7e9c17d

Please sign in to comment.