sendView
The sendView() method records a screen view on your mobile app. The screen view is 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
Viewmodifier helper. See Advanced usage > Using the SDK with SwiftUI.
Notes
- The SDK builds a synthetic URL for each screen view:
http://{appName}/{path}, whereappNamecomes from your app bundle (display name, or bundle name if missing), with spaces removed. WhenisPrefixingEnabledis true (the default),screenis inserted first, then your view name, for examplehttp://MyApp/screen/Welcome.