sendViews

The sendViews() method records a single hierarchical screen view on your mobile app. The values you pass are joined into one path (for example, screen/Onboarding/Welcome) and dispatched as a single event. Use it to group related screens under a logical hierarchy in reports.

Syntax

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

Parameters

  • views array<string>, required - Screen names from parent to child; the SDK joins them with / into one hierarchy and sends one event. Example: ["Settings", "Privacy", "Cookies"].

Notes

  • The SDK builds a synthetic URL for that screen view: http://{appName}/{path}, where appName comes from your app bundle (display name, or bundle name if missing), with spaces removed. When isPrefixingEnabled is true (the default), screen comes first, then your array values in order, for example http://MyApp/screen/Settings/Privacy/Cookies for ["Settings", "Privacy", "Cookies"].

Examples

To track a hierarchical screen view that combines Settings, Privacy, and Cookies into one path:

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 (here, the privacy & cookies screen under Settings):

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

Related methods