Skip to content

Commit

Permalink
Merge pull request #549 from SourcePointUSA/DIA-3524_support_uspstrin…
Browse files Browse the repository at this point in the history
…g_usnat

DIA-3524 support legacy uspstring in usnat
  • Loading branch information
andresilveirah committed Feb 23, 2024
2 parents b6e8499 + 270de6b commit 81512f9
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ class SPUserDefaults: SPLocalStorage {
Self.USER_DATA_KEY: userData,
Self.US_PRIVACY_STRING_KEY: usPrivacyString,
Self.LOCAL_STATE_KEY: localState
].merging(tcfData ?? [:]) { item, _ in item }}
]
.merging(tcfData ?? [:]) { item, _ in item }
.merging(gppData ?? [:]) { item, _ in item }
}

func clear() {
localState = nil
Expand Down
18 changes: 15 additions & 3 deletions ConsentViewController/Classes/SPCampaigns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,40 @@ public typealias SPTargetingParams = [String: String]
let GPPConfig: SPGPPConfig?

/**
Used by usNat campaigns only. Set this flag only if your app used an SDK older than `7.6.0`, use authenticated consent
Used by USNat campaigns only. Set this flag only if your app used an SDK older than `7.6.0`, use authenticated consent
and has a CCPA campaign.
*/
let transitionCCPAAuth: Bool?

/**
Used by USNat campaigns. Set this flag if you want to continue having the value `IABUSPrivacy_String`
stored in the `UserDefaults`. Useful during the transition between CCPA and USNat campaigns.
*/
let supportLegacyUSPString: Bool?

@objc override public var description: String {
"""
SPCampaign
- targetingParams: \(targetingParams)
- groupPmId: \(groupPmId as Any)
- GPPConfig: \(GPPConfig as Any)
- transitionCCPAAuth: \(transitionCCPAAuth as Any)
- supportLegacyUSPString: \(supportLegacyUSPString as Any)
"""
}

@nonobjc public init(
targetingParams: SPTargetingParams = [:],
groupPmId: String? = nil,
gppConfig: SPGPPConfig? = nil,
transitionCCPAAuth: Bool? = nil
transitionCCPAAuth: Bool? = nil,
supportLegacyUSPString: Bool? = nil
) {
self.targetingParams = targetingParams
self.groupPmId = groupPmId
self.GPPConfig = gppConfig
self.transitionCCPAAuth = transitionCCPAAuth
self.supportLegacyUSPString = supportLegacyUSPString
}

@available(swift, obsoleted: 1.0)
Expand All @@ -76,19 +85,22 @@ public typealias SPTargetingParams = [String: String]
self.groupPmId = groupPmId
self.GPPConfig = nil
self.transitionCCPAAuth = nil
self.supportLegacyUSPString = nil
}

@available(swift, obsoleted: 1.0)
@objc public init(
targetingParams: SPTargetingParams = [:],
groupPmId: String? = nil,
gppConfig: SPGPPConfig? = nil,
transitionCCPAAuth: SPOptinalBool = .unset
transitionCCPAAuth: SPOptinalBool = .unset,
supportLegacyUSPString: SPOptinalBool = .unset
) {
self.targetingParams = targetingParams
self.groupPmId = groupPmId
self.GPPConfig = gppConfig
self.transitionCCPAAuth = transitionCCPAAuth.boolValue
self.supportLegacyUSPString = supportLegacyUSPString.boolValue
}
}

Expand Down
11 changes: 11 additions & 0 deletions ConsentViewController/Classes/SPGPPConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import Foundation
let MspaOptOutOptionMode: SPMspaTernaryFlag?
let MspaServiceProviderMode: SPMspaTernaryFlag?

let uspString: Bool?

public init(
MspaCoveredTransaction: SPMspaBinaryFlag? = nil,
MspaOptOutOptionMode: SPMspaTernaryFlag? = nil,
Expand All @@ -50,6 +52,7 @@ import Foundation
self.MspaCoveredTransaction = MspaCoveredTransaction
self.MspaOptOutOptionMode = MspaOptOutOptionMode
self.MspaServiceProviderMode = MspaServiceProviderMode
uspString = nil
}

public init(
Expand All @@ -60,5 +63,13 @@ import Foundation
self.MspaCoveredTransaction = MspaCoveredTransaction
self.MspaOptOutOptionMode = MspaOptOutOptionMode
self.MspaServiceProviderMode = MspaServiceProviderMode
uspString = nil
}

init(uspString: Bool?) {
self.uspString = uspString
MspaCoveredTransaction = nil
MspaOptOutOptionMode = nil
MspaServiceProviderMode = nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ class SourcepointClientCoordinator: SPClientCoordinator {
self.propertyName = propertyName
self.language = language
self.campaigns = campaigns
self.includeData = IncludeData(gppConfig: campaigns.ccpa?.GPPConfig ?? SPGPPConfig())
self.includeData = IncludeData(
gppConfig: campaigns.ccpa?.GPPConfig ??
SPGPPConfig(uspString: campaigns.usnat?.supportLegacyUSPString)
)
self.storage = storage
self.spClient = spClient ?? SourcePointClient(
accountId: accountId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@ class SPClientCoordinatorSpec: QuickSpec {
coordinator = coordinatorFor(campaigns: SPCampaigns(usnat: SPCampaign()))
}

it("can support legacy uspstring") {
coordinator = coordinatorFor(
campaigns: SPCampaigns(
usnat: SPCampaign(supportLegacyUSPString: true)
)
)
waitUntil { done in
coordinator.loadMessages(forAuthId: nil, pubData: nil) { _ in
expect(
coordinator.userData.usnat?.consents?.GPPData?["IABUSPrivacy_String"]?.stringValue
).notTo(beEmpty())
done()
}
}
}

describe("with authId") {
it("persists consent even after cleaning all data") {
waitUntil { done in
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,17 @@ var consentManager = SPConsentManager(
)
```

## Support U.S. Privacy (Legacy) with U.S. Multi-State Privacy

If you're transitioning from U.S. Privacy (Legacy) to U.S. Multi-State Privacy, you may want to continue supporting the legacy US privacy string (`IABUSPrivacy_String`).
To do so, when instantiating the SDK, make sure to set the flag `.supportLegacyUSPString` to true. Example:
```swift
var consentManager = SPConsentManager(
...
campaigns: SPCampaigns(usnat: SPCampaign(supportLegacyUSPString: true)), // <== here
delegate: self
)
```

## Configuring the Message/Consents timeout

Expand Down

0 comments on commit 81512f9

Please sign in to comment.