sendViews

The sendViews() method records a screen view in your mobile app together with its navigation path. The values you pass are joined into a single path, for example screen/Onboarding/Welcome, and sent as a single event. Use this method to group related screens in reports.

Syntax

PiwikTracker.sharedInstance()?.sendViews(views: ["Onboarding", "Welcome"])
[[PiwikTracker sharedInstance] sendViews:@[@"Onboarding", @"Welcome"]];

Parameters

  • views (array<string>, required)
    Screen names in navigation order, from the parent screen to the current screen. The SDK joins them with / into a single path and sends one event. Example: ["Settings", "Privacy", "Cookies"].

Notes

  • The SDK builds a synthetic URL for that screen view:http://{appName}/{path}. The appName value comes from your app bundle. The SDK uses the display name or, if unavailable, the bundle name. Spaces are removed. By default, isPrefixingEnabled is true, so the SDK inserts screen before the values in the views array. For example, ["Settings", "Privacy", "Cookies"] becomes http://MyApp/screen/Settings/Privacy/Cookies.

Examples

To track a screen view for the navigation path Settings > Privacy > Cookies:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    PiwikTracker.sharedInstance()?.sendViews(views: ["Settings", "Privacy", "Cookies"])
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[PiwikTracker sharedInstance] sendViews:@[@"Settings", @"Privacy", @"Cookies"]];
}

Call sendViews() from the .onAppear modifier on the view that represents that hierarchy. In this example, that view is the Privacy and Cookies screen under Settings:

struct SettingsPrivacyCookiesView: View {
    var body: some View {
        Text("Privacy & cookies")
            .onAppear {
                PiwikTracker.sharedInstance()?
                    .sendViews(views: ["Settings", "Privacy", "Cookies"])
            }
    }
}

Related methods


Did this page help you?