setVisitorIdFrom
The setVisitorIdFrom methods read the pk_vid query parameter from a URL. If it is valid, the SDK uses the same rules as setVisitorID to set the visitor ID.
Call setVisitorIdFrom(deepLink:) or setVisitorIdFrom(url:) when the user opens your app from a link that carries pk_vid, for example a universal / app link opened in Safari or another browser on the same phone, or a link followed from an in-app web view. That way you can reuse the same visitor ID for the website (or web content) and the app on that phone.
Syntax
let stringResult = PiwikTracker.sharedInstance()?.setVisitorIdFrom(deepLink: "deepLink") ?? false
let urlResult = PiwikTracker.sharedInstance()?.setVisitorIdFrom(url: url) ?? falseBOOL result = [[PiwikTracker sharedInstance] setVisitorIdFromDeepLink:@"deepLink"];
BOOL result = [[PiwikTracker sharedInstance] setVisitorIdFromURL:url];Parameters
- deepLink (string, optional)
A URL string that the system can parse. It must include apk_vidquery parameter. The first 16 characters ofpk_vidmust be a valid visitor ID in lowercase hexadecimal (0-9,a-f) and satisfy the same validation rules asvisitorID. Example:piwik://example?pk_vid=25a3c7d060a94360. - url (URL, optional)
Same requirements as deepLink, provided as anNSURL/URLvalue.
Returns
-
true: The visitor ID was updated frompk_vid. -
false: The visitor ID was not updated because:- The URL is missing or invalid.
- The URL doesn't contain
pk_vid. - The
pk_vidvalue is shorter than 16 characters. - The first 16 characters of
pk_vidaren't valid lowercase hexadecimal characters. See visitorID.
Examples
To set the visitor ID from a deep link delivered to application(_:open:options:):
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return PiwikTracker.sharedInstance()?.setVisitorIdFrom(url: url) ?? false
}- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
return [[PiwikTracker sharedInstance] setVisitorIdFromURL:url];
}Attach the .onOpenURL modifier to the root view of your App:
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
PiwikTracker.sharedInstance()?.setVisitorIdFrom(url: url)
}
}
}
}To set the visitor ID from a string-based deep link:
PiwikTracker.sharedInstance()?.setVisitorIdFrom(deepLink: "piwik://example?pk_vid=25a3c7d060a94360")[[PiwikTracker sharedInstance] setVisitorIdFromDeepLink:@"piwik://example?pk_vid=25a3c7d060a94360"];Notes
- If
pk_vidis longer than 16 characters, only the first 16 characters are used. Those characters must still satisfy the hexadecimal format requirements. - For cross-platform flows, see cross-platform tracking.
Related methods
Updated 2 months ago