In your Podfile
add the following line to your app target:
pod 'ConsentViewController', '5.3.3'
We also support Carthage. It requires a couple more steps to install so we dedicated a whole wiki page for it. Let us know if we missed any step.
We also support Swift Package Manager. It is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but SourcePoint does support its use on iOS platform.
To add our SDK package as dependency to your Xcode project, In Xcode select File > Swift Packages > Add Package Dependency and enter our SDK repository URL.
https://github.com/SourcePointUSA/ios-cmp-app.git
It's pretty simple, here are 5 easy steps for you:
- implement the
GDPRConsentDelegate
protocol - instantiate the
GDPRConsentViewController
with your Account ID, property id, property, privacy manager id, campaign environment, a flag to show the privacy manager directly or not and the consent delegate - call
.loadMessage()
- present the controller when the message is ready to be displayed
- profit!
import ConsentViewController
class ViewController: UIViewController {
lazy var consentViewController: GDPRConsentViewController = { return GDPRConsentViewController(
accountId: 22,
propertyId: 7639,
propertyName: try! GDPRPropertyName("tcfv2.mobile.webview"),
PMId: "122058",
campaignEnv: .Public,
consentDelegate: self
)}()
@IBAction func onPrivacySettingsTap(_ sender: Any) {
consentViewController.loadPrivacyManager()
}
override func viewDidLoad() {
super.viewDidLoad()
consentViewController.loadMessage()
}
}
extension ViewController: GDPRConsentDelegate {
func gdprConsentUIWillShow() {
present(consentViewController, animated: true, completion: nil)
}
func consentUIDidDisappear() {
dismiss(animated: true, completion: nil)
}
func onConsentReady(gdprUUID: GDPRUUID, userConsent: GDPRUserConsent) {
print("ConsentUUID: \(gdprUUID)")
userConsent.acceptedVendors.forEach { vendorId in print("Vendor: \(vendorId)") }
userConsent.acceptedCategories.forEach { purposeId in print("Purpose: \(purposeId)") }
// IAB Related Data
print(UserDefaults.standard.dictionaryWithValues(forKeys: userConsent.tcfData.dictionaryValue?.keys.sorted() ?? []))
}
func onError(error: GDPRConsentViewControllerError?) {
print("Error: \(error.debugDescription)")
}
}
#import "ViewController.h"
@import ConsentViewController;
@interface ViewController ()<GDPRConsentDelegate> {
GDPRConsentViewController *cvc;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
GDPRPropertyName *propertyName = [[GDPRPropertyName alloc] init:@"tcfv2.mobile.webview" error:NULL];
cvc = [[GDPRConsentViewController alloc]
initWithAccountId: 22
propertyId: 7639
propertyName: propertyName
PMId: @"122058"
campaignEnv: GDPRCampaignEnvPublic
consentDelegate: self];
[cvc loadMessage];
}
- (void)onConsentReadyWithGdprUUID:(NSString *)gdprUUID userConsent:(GDPRUserConsent *)userConsent {
NSLog(@"ConsentUUID: %@", gdprUUID);
NSLog(@"ConsentString: %@", userConsent.euconsent);
for (id vendorId in userConsent.acceptedVendors) {
NSLog(@"Consented to Vendor(id: %@)", vendorId);
}
for (id purposeId in userConsent.acceptedCategories) {
NSLog(@"Consented to Purpose(id: %@)", purposeId);
}
}
- (void)gdprConsentUIWillShow {
[self presentViewController:cvc animated:true completion:NULL];
}
- (void)consentUIDidDisappear {
[self dismissViewControllerAnimated:true completion:nil];
}
@end
It's possible to programatically consent the current user to a list of custom vendors, categories and legitimate interest caregories with the method:
func customConsentTo(
vendors: [String],
categories: [String],
legIntCategories: [String],
completionHandler: @escaping (GDPRUserConsent) -> Void)
The ids passed will be appended to the list of already accepted vendors, categories and leg. int. categories. The method is asynchronous so you must pass a completion handler that will receive back an instance of GDPRUserConsent
in case of success or it'll call the delegate method onError
in case of failure.
It's important to notice, this method is intended to be used for custom vendors and purposes only. For IAB vendors and purposes, it's still required to get consent via the consent message or privacy manager.
In order to use the authenticated consent all you need to do is replace .loadMessage()
with .loadMessage(forAuthId: String)
. Example:
consentViewController.loadMessage(forAuthId: "JohnDoe")
In Obj-C that'd be:
[consentViewController loadMessage forAuthId: @"JohnDoe"]
This way, if we already have consent for that token ("JohDoe"
) we'll bring the consent profile from the server, overwriting whatever was stored in the device.
More about the authId
below.
let webview = WKWebView()
webview.setConsentFor(authId: String)
webview.load(URLRequest)
This feature makes use of what we call Authenticated Consent. In a nutshell, you provide an identifier for the current user (username, user id, uuid or any unique string) and we'll take care of associating the consent profile to that identifier. The authId will then assume 1 of the 3 values below:
- User is authenticated and have an id:
In that case the
authId
is going to be that user id. - User is not authenticated and I'm only interested in using consent in this app.
We recommend using a randomly generated
UUID
asauthId
. Make sure to persist thisauthId
and always call the.loadMessage(forAuthId: String)
- User is not authenticated and I want the consent to be shared across apps I controll. In this case, you'll need an identifier that is guaranteed to be the same across apps you control. That's exactly what the IDFV (Identifier for Vendor) is for. You don't need to store this id as it remains the same across app launches.
// let authId = // my user id
// let authId = // stored uuid || UUID().uuidString
let authId = UIDevice().identifierForVendor
consentViewController.loadMessage(forAuthId: myAuthId)
// after the `onConsentReady` is called
myWebView.setConsentFor(authId: authid)
myWebView.load(urlRequest)
A few remarks:
- The web content being loaded (web property) needs to share the same vendor list as the app.
- The vendor list's consent scope needs to be set to Shared Site instead of Single Site
By default, the SDK will instruct the message to render itself using the locale defined by the WKWebView
. If you wish to overwrite this behaviour and force a message to be displayed in a certain language, you need to set the .messageLanguage
attribute of the GDPRConsentViewController
before calling .loadMessage() / .loadPrivacyManager()
.
consentViewController.messageLanguage = .German
consentViewController.loadMessage()
It's important to notice that if any of the components of the message doesn't have a translation for that language, the component will be rendered in english as a fallback.
In order to set a targeting param all you need to do is passing targetingParams:[string:string]
as a parametter in the ConsentViewController constructor. Example:
lazy var consentViewController: GDPRConsentViewController = { return GDPRConsentViewController(
//other parametters here...
targetingParams:["language":"fr"]
)}()
In this example a key/value pair "language":"fr" is passed to the sp scenario and can be useded, wiht the proper scenario setup, to show a french message instead of a english one.
Before calling .loadMessage
or .loadPrivacyManager
, set the .messageTimeoutInSeconds
attribute to a time interval that makes most sense for your own application. By default, we set it to 30 seconds.
In case of a timeout error, the onError
callback will be called and the consent flow will stop there.
When the user takes an action within the consent UI, it's possible to attach an arbitrary payload to the action data an have it sent to our endpoints. For more information on how to do that check our wiki: Sending arbitrary data when the user takes an action
Have a look at this neat wiki we put together.
The SDK is pretty slim, there are no assets, no dependencies, just pure code. Since we use Swift, its size will vary depending on the configuration of your project but it should not exceed 2 MB
.
Although our SDK can be technically added to projects targeting iOS 9, we support iOS >= 10 only.
We'll update this list over time, if you have any questions feel free to open an issue or concact your SourcePoint account manager.