{"_id":"5ab565f212d24900747242af","category":{"_id":"5ab565f112d249007472429b","version":"5ab565f112d2490074724298","project":"57c88b374434350e00509d7f","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-05T21:53:37.386Z","from_sync":false,"order":2,"slug":"reference","title":"Reference"},"project":"57c88b374434350e00509d7f","parentDoc":null,"user":"55e5ba046015ce1900eadb8e","version":{"_id":"5ab565f112d2490074724298","project":"57c88b374434350e00509d7f","__v":1,"createdAt":"2018-03-23T20:39:13.299Z","releaseDate":"2018-03-23T20:39:13.299Z","categories":["5ab565f112d2490074724299","5ab565f112d249007472429a","5ab565f112d249007472429b","5ab565f112d249007472429c"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.6.0","version":"3.6.0"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-03-21T09:58:46.355Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":13,"body":"The Primer iOS SDK automatically handles install attribution for all new installs, and provides an interface to access all related information.\n\n####Retrieve Information\n\nOnce the SDK is initialized, you can query both the install and the latest attribution information in an asynchronous manner. After the SDK synced with our servers this will return the information instantly. Once you receive the `PMRAttribution` instance, you can access attribution properties:\n* whether it's a referral\n* the deep link\n* the name and key of the targeting\n* the name of the source\n* the name of the link\n* the attribution parameters\n* the user properties of the sender\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Get install attribution information\\n\\n[Primer getInstallAttributionWithCompletion:^(PMRAttribution *attribution) {\\n    // Access attribution's properties\\n}];\\n\\n// Get latest attribution information\\n\\n[Primer getLatestAttributionWithCompletion:^(PMRAttribution *attribution) {\\n    // Access attribution's properties\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"// Get install attribution information\\n\\nPrimer.getInstallAttribution { (attribution: PMRAttribution) in\\n    // Access attribution's properties\\n}\\n\\n// Get latest attribution information\\n\\nPrimer.getLatestAttribution { (attribution: PMRAttribution) in\\n    // Access attribution's properties\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n####Universal Links\n\nWhile Smart Links are a nice way to attribute your users, the post-installation routing between applications got more complicated with iOS 9.2 and above. To make this process easier the SDK now supports Universal Links. All you need to do is set them up in your application, and turn them on at the Dashboard, under the App Store URLs tab in your Project Settings.\n\nThen just implement the `-application:continueUserActivity:restorationHandler:` method in your app delegate, and let Primer check and handle the user activity. It will return whether the user comes from a Smart Link that the SDK can handle.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {\\n    BOOL handled = [Primer continueUserActivity:userActivity];\\n    return handled;\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: :::at:::escaping ([Any]?) -> Void) -> Bool {\\n    let handled = Primer.continue(userActivity)\\n    return handled\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nIf you'd like to get more information about this, please take a look at our [Universal Links Guide](doc:universal-links-guide)!\n\n####IDFA\n\nThe Primer iOS SDK automatically sends the IDFA (identifier for advertisers) with all events. This improves attribution accuracy for installs and referrers. However, if you'd like to disable this feature you can do so:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Primer setShouldUseIDFA:NO];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"Primer.setShouldUseIDFA(false)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nNote that if you opt-out of this the SDK does not need the `AdSupport.framework`, so you can switch to the `Primer/NoIDFA` subspec - for CocoaPods integrations, or simply remove it - for manual and Carthage integrations.\n\n####Sanitization\n\nBy default the SDK sends some parameters with events and API calls that are useful for real life debugging and analytics scenarios. If this collides with your end user agreement you have the option to sanitize them.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Primer setSanitizeEnabled:YES];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"Primer.setSanitizeEnabled(true)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n####Delayed Launch\n\nIn case you wish to do your own attribution server call, and then provide this information to the Primer SDK once available, a delayed SDK launch is possible. Just turn it on using the `+setDelayedLaunchEnabled:` method before starting the SDK, then do a manual launch with `+delayedLaunchWithOptions:`.\n\nCurrently the only supported solution is Facebook's Deferred App Link URL, with the help of the `PMRLaunchOptionsDeferredAppLinkURLKey` key. To use it, just add the following to your app:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Primer setDelayedLaunchEnabled:YES];\\n[Primer startWithToken:@\\\"[[app:token]]\\\"];\\n\\n[FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) {\\n    NSDictionary *options;\\n    \\n    if (url != nil) {\\n        options = @{PMRLaunchOptionsDeferredAppLinkURLKey: url};\\n    }\\n    \\n    [Primer delayedLaunchWithOptions:options];\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"Primer.setDelayedLaunchEnabled(true)\\nPrimer.start(withToken: \\\"[[app:token]]\\\")\\n\\nFBSDKAppLinkUtility.fetchDeferredAppLink { (url: URL?, error: Error?) in\\n    var options: [String : Any]?\\n    \\n    if url != nil {\\n        options = [PMRLaunchOptionsDeferredAppLinkURLKey: url!]\\n    }\\n    \\n    Primer.delayedLaunch(options: options)\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"attribution","type":"basic","title":"Attribution"}
The Primer iOS SDK automatically handles install attribution for all new installs, and provides an interface to access all related information. ####Retrieve Information Once the SDK is initialized, you can query both the install and the latest attribution information in an asynchronous manner. After the SDK synced with our servers this will return the information instantly. Once you receive the `PMRAttribution` instance, you can access attribution properties: * whether it's a referral * the deep link * the name and key of the targeting * the name of the source * the name of the link * the attribution parameters * the user properties of the sender [block:code] { "codes": [ { "code": "// Get install attribution information\n\n[Primer getInstallAttributionWithCompletion:^(PMRAttribution *attribution) {\n // Access attribution's properties\n}];\n\n// Get latest attribution information\n\n[Primer getLatestAttributionWithCompletion:^(PMRAttribution *attribution) {\n // Access attribution's properties\n}];", "language": "objectivec" }, { "code": "// Get install attribution information\n\nPrimer.getInstallAttribution { (attribution: PMRAttribution) in\n // Access attribution's properties\n}\n\n// Get latest attribution information\n\nPrimer.getLatestAttribution { (attribution: PMRAttribution) in\n // Access attribution's properties\n}", "language": "swift" } ] } [/block] ####Universal Links While Smart Links are a nice way to attribute your users, the post-installation routing between applications got more complicated with iOS 9.2 and above. To make this process easier the SDK now supports Universal Links. All you need to do is set them up in your application, and turn them on at the Dashboard, under the App Store URLs tab in your Project Settings. Then just implement the `-application:continueUserActivity:restorationHandler:` method in your app delegate, and let Primer check and handle the user activity. It will return whether the user comes from a Smart Link that the SDK can handle. [block:code] { "codes": [ { "code": "- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {\n BOOL handled = [Primer continueUserActivity:userActivity];\n return handled;\n}", "language": "objectivec" }, { "code": "func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {\n let handled = Primer.continue(userActivity)\n return handled\n}", "language": "swift" } ] } [/block] If you'd like to get more information about this, please take a look at our [Universal Links Guide](doc:universal-links-guide)! ####IDFA The Primer iOS SDK automatically sends the IDFA (identifier for advertisers) with all events. This improves attribution accuracy for installs and referrers. However, if you'd like to disable this feature you can do so: [block:code] { "codes": [ { "code": "[Primer setShouldUseIDFA:NO];", "language": "objectivec" }, { "code": "Primer.setShouldUseIDFA(false)", "language": "swift" } ] } [/block] Note that if you opt-out of this the SDK does not need the `AdSupport.framework`, so you can switch to the `Primer/NoIDFA` subspec - for CocoaPods integrations, or simply remove it - for manual and Carthage integrations. ####Sanitization By default the SDK sends some parameters with events and API calls that are useful for real life debugging and analytics scenarios. If this collides with your end user agreement you have the option to sanitize them. [block:code] { "codes": [ { "code": "[Primer setSanitizeEnabled:YES];", "language": "objectivec" }, { "code": "Primer.setSanitizeEnabled(true)", "language": "swift" } ] } [/block] ####Delayed Launch In case you wish to do your own attribution server call, and then provide this information to the Primer SDK once available, a delayed SDK launch is possible. Just turn it on using the `+setDelayedLaunchEnabled:` method before starting the SDK, then do a manual launch with `+delayedLaunchWithOptions:`. Currently the only supported solution is Facebook's Deferred App Link URL, with the help of the `PMRLaunchOptionsDeferredAppLinkURLKey` key. To use it, just add the following to your app: [block:code] { "codes": [ { "code": "[Primer setDelayedLaunchEnabled:YES];\n[Primer startWithToken:@\"[[app:token]]\"];\n\n[FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) {\n NSDictionary *options;\n \n if (url != nil) {\n options = @{PMRLaunchOptionsDeferredAppLinkURLKey: url};\n }\n \n [Primer delayedLaunchWithOptions:options];\n}];", "language": "objectivec" }, { "code": "Primer.setDelayedLaunchEnabled(true)\nPrimer.start(withToken: \"[[app:token]]\")\n\nFBSDKAppLinkUtility.fetchDeferredAppLink { (url: URL?, error: Error?) in\n var options: [String : Any]?\n \n if url != nil {\n options = [PMRLaunchOptionsDeferredAppLinkURLKey: url!]\n }\n \n Primer.delayedLaunch(options: options)\n}", "language": "swift" } ] } [/block]