Skip to content

Commit

Permalink
refactor: add privacy manifest file and remove tracking IDs (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seavenly authored Apr 18, 2024
1 parent 610d9e3 commit 8400d96
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 94 deletions.
2 changes: 1 addition & 1 deletion PayPalMessages.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Pod::Spec.new do |s|

s.source_files = "Sources/PayPalMessages/**/*.swift"
s.resource_bundle = {
"PayPalMessages" => ['Sources/PayPalMessages/*.xcassets']
"PayPalMessages" => ['Sources/PayPalMessages/*.xcassets', 'Sources/PayPalMessages/PrivacyInfo.xcprivacy']
}
end
4 changes: 4 additions & 0 deletions PayPalMessages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
C61D84472B33348C00F372EF /* CloudEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C61D84462B33348C00F372EF /* CloudEvent.swift */; };
C62FF8232B742C9400890823 /* ResponseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C62FF8222B742C9400890823 /* ResponseError.swift */; };
C62FF8252B74315B00890823 /* ResponseErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C62FF8242B74315B00890823 /* ResponseErrorTests.swift */; };
C62FF8272B852E4000890823 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = C62FF8262B852E4000890823 /* PrivacyInfo.xcprivacy */; };
C635F4362A9645B10096F9FF /* PayPalMessages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C635F42E2A9645B10096F9FF /* PayPalMessages.framework */; };
C635F4C12A964A020096F9FF /* PayPalMessageModalViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F48E2A964A020096F9FF /* PayPalMessageModalViewModel.swift */; };
C635F4C32A964A020096F9FF /* AnalyticsEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F4912A964A020096F9FF /* AnalyticsEvent.swift */; };
Expand Down Expand Up @@ -91,6 +92,7 @@
C61D84462B33348C00F372EF /* CloudEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloudEvent.swift; sourceTree = "<group>"; };
C62FF8222B742C9400890823 /* ResponseError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseError.swift; sourceTree = "<group>"; };
C62FF8242B74315B00890823 /* ResponseErrorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseErrorTests.swift; sourceTree = "<group>"; };
C62FF8262B852E4000890823 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
C635F42E2A9645B10096F9FF /* PayPalMessages.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PayPalMessages.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C635F4352A9645B10096F9FF /* PayPalMessagesTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PayPalMessagesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C635F48E2A964A020096F9FF /* PayPalMessageModalViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayPalMessageModalViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -220,6 +222,7 @@
C635F4AC2A964A020096F9FF /* Utils */,
C635F4BE2A964A020096F9FF /* Views */,
C635F4AB2A964A020096F9FF /* Assets.xcassets */,
C62FF8262B852E4000890823 /* PrivacyInfo.xcprivacy */,
C635F4C02A964A020096F9FF /* PayPalMessageModal.swift */,
C635F48E2A964A020096F9FF /* PayPalMessageModalViewModel.swift */,
C635F4982A964A020096F9FF /* PayPalMessageView.swift */,
Expand Down Expand Up @@ -460,6 +463,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C62FF8272B852E4000890823 /* PrivacyInfo.xcprivacy in Resources */,
C635F4DA2A964A020096F9FF /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 0 additions & 2 deletions Sources/PayPalMessages/Analytics/AnalyticsLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Weak<T: AnyObject> {
class AnalyticsLogger: Encodable {

// Global Details
static var deviceID: String? = UIDevice.current.identifierForVendor?.uuidString
static var sessionID: String = UUID().uuidString
static var integrationVersion: String?
static var integrationName: String?

Expand Down
4 changes: 0 additions & 4 deletions Sources/PayPalMessages/Analytics/CloudEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class CloudEvent: Encodable {

var dataContainer = container.nestedContainer(keyedBy: IntegrationKey.self, forKey: .data)

try dataContainer.encodeIfPresent(AnalyticsLogger.deviceID, forKey: .deviceID)
try dataContainer.encodeIfPresent(AnalyticsLogger.sessionID, forKey: .sessionID)
try dataContainer.encodeIfPresent(AnalyticsLogger.integrationVersion, forKey: .integrationVersion)
try dataContainer.encodeIfPresent(AnalyticsLogger.integrationName, forKey: .integrationName)

Expand Down Expand Up @@ -142,8 +140,6 @@ class CloudEvent: Encodable {
case partnerAttributionID = "partner_attribution_id"
case merchantProfileHash = "merchant_profile_hash"
// Global Details
case deviceID = "device_id"
case sessionID = "session_id"
case integrationVersion = "integration_version"
case integrationName = "integration_name"
// Build Details
Expand Down
12 changes: 1 addition & 11 deletions Sources/PayPalMessages/Config/PayPalMessageConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,9 @@ public class PayPalMessageConfig: NSObject {

public static func setGlobalAnalytics(
integrationName: String,
integrationVersion: String,
deviceID: String? = nil,
sessionID: String? = nil
integrationVersion: String
) {
AnalyticsLogger.integrationName = integrationName
AnalyticsLogger.integrationVersion = integrationVersion

if let deviceID {
AnalyticsLogger.deviceID = deviceID
}

if let sessionID {
AnalyticsLogger.sessionID = sessionID
}
}
}
8 changes: 2 additions & 6 deletions Sources/PayPalMessages/Config/PayPalMessageModalConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,11 @@ class PayPalMessageModalConfig: NSObject, Encodable {

public static func setGlobalAnalytics(
integrationName: String,
integrationVersion: String,
deviceID: String? = nil,
sessionID: String? = nil
integrationVersion: String
) {
PayPalMessageConfig.setGlobalAnalytics(
integrationName: integrationName,
integrationVersion: integrationVersion,
deviceID: deviceID,
sessionID: sessionID
integrationVersion: integrationVersion
)
}

Expand Down
4 changes: 1 addition & 3 deletions Sources/PayPalMessages/IO/MessageRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ class MessageRequest: MessageRequestable {
"instance_id": parameters.instanceID,
"version": BuildInfo.version,
"integration_type": BuildInfo.integrationType,
"integration_version": AnalyticsLogger.integrationVersion,
"device_id": AnalyticsLogger.deviceID,
"session_id": AnalyticsLogger.sessionID
"integration_version": AnalyticsLogger.integrationVersion
].filter {
guard let value = $0.value else { return false }

Expand Down
2 changes: 0 additions & 2 deletions Sources/PayPalMessages/PayPalMessageModalViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
"integration_identifier": integrationIdentifier,
"ignore_cache": ignoreCache?.description,
"integration_version": AnalyticsLogger.integrationVersion,
"device_id": AnalyticsLogger.deviceID,
"session_id": AnalyticsLogger.sessionID,
"features": "native-modal"
].filter {
guard let value = $0.value else { return false }
Expand Down
36 changes: 36 additions & 0 deletions Sources/PayPalMessages/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeProductInteraction</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<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>
<key>NSPrivacyTrackingDomains</key>
<array/>
<key>NSPrivacyTracking</key>
<false/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PayPalMessageRequestMock: MessageRequestable {
}

if case .success(messageResponse: let messageResponse) = scenario, let messageResponse {
return messageResponse
return messageResponse
}

return MessageResponse(
Expand Down
21 changes: 0 additions & 21 deletions Tests/PayPalMessagesTests/PayPalMessageConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,14 @@ import XCTest
func testSetGlobalAnalytics() {
let integrationName = "MyIntegration"
let integrationVersion = "1.0"
let deviceID = "Device123"
let sessionID = "Session456"

PayPalMessageModalConfig.setGlobalAnalytics(
integrationName: integrationName,
integrationVersion: integrationVersion,
deviceID: deviceID,
sessionID: sessionID
)

XCTAssertEqual(AnalyticsLogger.integrationName, integrationName)
XCTAssertEqual(AnalyticsLogger.integrationVersion, integrationVersion)
XCTAssertEqual(AnalyticsLogger.deviceID, deviceID)
XCTAssertEqual(AnalyticsLogger.sessionID, sessionID)
}

func testSetGlobalAnalyticsWithDefaults() {
let integrationName = "MyIntegration"
let integrationVersion = "1.0"

PayPalMessageConfig.setGlobalAnalytics(
integrationName: integrationName,
integrationVersion: integrationVersion
)

XCTAssertEqual(AnalyticsLogger.integrationName, integrationName)
XCTAssertEqual(AnalyticsLogger.integrationVersion, integrationVersion)
XCTAssertNil(AnalyticsLogger.deviceID)
XCTAssertNil(AnalyticsLogger.sessionID)
}

func testStandardIntegrationInitialization() {
Expand Down
44 changes: 1 addition & 43 deletions Tests/PayPalMessagesTests/PayPalMessageLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ final class PayPalMessageLoggerTests: XCTestCase {

PayPalMessageConfig.setGlobalAnalytics(
integrationName: "Test_SDK",
integrationVersion: "0.1.0",
deviceID: "987654321",
sessionID: "123456789"
integrationVersion: "0.1.0"
)

// Inject mock sender to intercept log requests
Expand Down Expand Up @@ -88,8 +86,6 @@ final class PayPalMessageLoggerTests: XCTestCase {
"client_id": "testloggerclientid",
"merchant_profile_hash": "TEST_HASH",
"integration_version": "0.1.0",
"device_id": "987654321",
"session_id": "123456789",
"components": [
[
"amount": 50,
Expand Down Expand Up @@ -162,8 +158,6 @@ final class PayPalMessageLoggerTests: XCTestCase {
"integration_type": "NATIVE_IOS",
"client_id": "testloggerclientid",
"integration_version": "0.1.0",
"device_id": "987654321",
"session_id": "123456789",
"components": [
[
"amount": 50,
Expand Down Expand Up @@ -232,8 +226,6 @@ final class PayPalMessageLoggerTests: XCTestCase {
"client_id": "testloggerclientid",
"merchant_profile_hash": "TEST_HASH",
"integration_version": "0.1.0",
"device_id": "987654321",
"session_id": "123456789",
"components": [
[
"amount": 50,
Expand Down Expand Up @@ -301,8 +293,6 @@ final class PayPalMessageLoggerTests: XCTestCase {
"client_id": "testloggerclientid",
"merchant_profile_hash": "TEST_HASH",
"integration_version": "0.1.0",
"device_id": "987654321",
"session_id": "123456789",
"components": [
[
"amount": 50,
Expand Down Expand Up @@ -359,8 +349,6 @@ final class PayPalMessageLoggerTests: XCTestCase {
"client_id": "testloggerclientid",
"merchant_profile_hash": "TEST_HASH",
"integration_version": "0.1.0",
"device_id": "987654321",
"session_id": "123456789",
"components": [
[
"amount": 50,
Expand Down Expand Up @@ -426,8 +414,6 @@ final class PayPalMessageLoggerTests: XCTestCase {
"client_id": "testloggerclientid2",
"merchant_profile_hash": "TEST_HASH",
"integration_version": "0.1.0",
"device_id": "987654321",
"session_id": "123456789",
"components": [
[
"amount": 100,
Expand Down Expand Up @@ -485,34 +471,6 @@ final class PayPalMessageLoggerTests: XCTestCase {
XCTAssert(clientID1 == "testloggerclientid3" || clientID2 == "testloggerclientid3")
}

func testNilDeviceIDDoesNotOverwrite() {
PayPalMessageConfig.setGlobalAnalytics(
integrationName: "Test_SDK",
integrationVersion: "0.1.0"
)

let messageLogger = AnalyticsLogger(.message(Weak(message)))

messageLogger.addEvent(.messageRender(renderDuration: 10, requestDuration: 15))

AnalyticsService.shared.flushEvents()

guard let data = mockSender.calls.last,
let data = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
return XCTFail("invalid JSON data")
}

guard let deviceID = (data["data"] as? [String: Any])?["device_id"] as? String else {
return XCTFail("missing device_id")
}
guard let sessionID = (data["data"] as? [String: Any])?["session_id"] as? String else {
return XCTFail("missing session_id")
}

XCTAssert(deviceID == "987654321")
XCTAssert(sessionID == "123456789")
}

// MARK: - Helper assert functions

private func assert(payload: [String: Any], equals expectedPayload: [String: Any]) {
Expand Down

0 comments on commit 8400d96

Please sign in to comment.