sendView

The sendView() method records a screen view in your mobile app, similar to the page view on a website.

Syntax

Call sendView(view:) when the screen appears, for example from the .onAppear modifier on a View or from viewDidAppear in a UIViewController.

struct WelcomeView: View {
    var body: some View {
        Text("Welcome")
            .onAppear {
                PiwikTracker.sharedInstance()?.sendView(view: "view")
            }
    }
}
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    PiwikTracker.sharedInstance()?.sendView(view: "view")
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[PiwikTracker sharedInstance] sendView:@"view"];
}

Parameters

  • view (string, required)
    The name of the screen to track. Example: Welcome.

Examples

Use .onAppear for a View named Welcome:

struct WelcomeView: View {
    var body: some View {
        Text("Welcome")
            .onAppear {
                PiwikTracker.sharedInstance()?.sendView(view: "Welcome")
            }
    }
}

From viewDidAppear in a view controller:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    PiwikTracker.sharedInstance()?.sendView(view: "Welcome")
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[PiwikTracker sharedInstance] sendView:@"Welcome"];
}

Tip: If you track many screens, define a small View modifier helper. See Advanced usage > Using the SDK with SwiftUI.

Notes

  • The SDK builds a synthetic URL for each screen view: http://{appName}/{path}. The appName comes from your app bundle. The SDK uses the display name or, if unavailable, a bundle name. Spaces are removed. By default, isPrefixingEnabled is true, so the SDK inserts screen before the view name. For example: http://MyApp/screen/Welcome.

Related methods


Did this page help you?