sendCampaign
The sendCampaign() method tracks online campaigns that bring traffic to your mobile app. To track a campaign, you need to add campaign parameters to each campaign link and then use this method to pass that data. The method itself does not send any event - the campaign parameters are stored and attached to the next event that the SDK sends (for example, a screen view), and then cleared.
Syntax
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return PiwikTracker.sharedInstance()?.sendCampaign(url: url.absoluteString) ?? false
}- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
return [[PiwikTracker sharedInstance] sendCampaign:url.absoluteString];
}Parameters
- url
string, required- The URL you used in your campaign to bring traffic to your mobile app. Any URL containing query parameters in the form?key=value&key=valueis accepted, including custom URL schemes used for deep links. Example:http://example.com?pk_campaign=Summer_Promo&pk_keyword=banking_app.
Examples
To pass campaign data from the campaign link http://example.com?pk_campaign=Summer_Promo&pk_keyword=banking_app when the system delivers it to application(_:open:options:):
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return PiwikTracker.sharedInstance()?.sendCampaign(url: url.absoluteString) ?? false
}- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
return [[PiwikTracker sharedInstance] sendCampaign:url.absoluteString];
}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()?.sendCampaign(url: url.absoluteString)
}
}
}
}Notes
- The SDK forwards every
key=valuepair from the URL query string to Piwik PRO. Which of those parameters are interpreted as campaign data is decided on the server side. - Piwik PRO recognizes the standard
pk_*andutm_*campaign parameters by default. For the full list of recognized parameters and instructions on how to add custom ones, see How can I customize Piwik PRO campaign parameters? and the Administration > Sites & apps > Data collection > Campaigns section. - The campaign URL must contain exactly one
?. URLs with multiple?characters are ignored.