Screens in Cocoa apps
Screens are the content that your users view in your app. Using Zoho Apptics' screen tracking, you can measure the screen views and associate the screen data with events. This helps you to understand user engagement and behaviour.
- Make sure that you have integrated Apptics with your app, refer to the integration guide for detailed steps.
- Once the integration is done, you can track the screens either manually or automatically.
Manual screen tracking
- You can track the screens manually and also provide custom screen names using Apptics.
- Use the below method to view the controller class that you want to track.
- To track the entry of the view, call the method viewDidAppear.
Copied#import <AppticsScreenTracker/AppticsScreenTracker.h>
Copiedimport AppticsScreenTracker
For SwiftUI
Use import Apptics_Swift.
Track screen entry
- To track when a view appears, call the trackViewEnter method within the viewDidAppear method of the view controller.
Copied[APScreentracker trackViewEnter:<#(nonnull NSString *)#>];
CopiedAPScreentracker.trackViewEnter(<#T##screenName: String##String#>)
Track screen exit
- To track when a view disappears, call the trackViewExit within the viewWillDisappear method.
Copied[APScreentracker trackViewExit:<#(nonnull NSString *)#>];
CopiedAPScreentracker.trackViewExit(<#T##screenName: String##String#>)
For SwiftUI
struct ContentView: View
{
var body: some View
{
NavigationView
{
navigationTitle("Table List View")
.trackScreen("Home screen")
}
}
}
Note: Make sure that screen name follow the below norms, else the event won't be logged within the SDK.
- screen name is mandatory and cannot be nil or empty.
- screen name should not be more than 250 characters.
- should start with an alphabet.
- only numbers, spaces, dots, and underscore are allowed after the first letter.
- cannot start with 'ap_' or 'AP_'. These are reserved for the defined events.
An example of a screen name : 'Hello World' , 'Hello_World' , 'hello.world'
An example of an invalid screen name : '_hello' , '1hello' , `Hello-World` , 'ap_hello`
Automatic screen tracking
We have disabled automatic screen tracking to avoid all screens getting tracked.
trackAllScreens property
The trackAllScreens property in the AppticsConfig class allows you to control the screen tracking when enableAutomaticScreenTracking is enabled.
- If trackAllScreens is set to true, the SDK will track all the screens automatically based on the enableAutomaticScreenTracking setting. This is helpful when you want to track all the screens without much intervention.
- If trackAllScreens is set to false (default), you will be able to track screens selectively by assigning screen names manually using the ap_screen_name.
Enable automatic screen tracking
Define screen name
- Add a property named ap_screen_name to view the controllers that are to be tracked automatically. Assign a meaningful name to the ap_screen_name variable.
Example
Copied@property (nonatomic, retain) NSString *ap_screen_name;
Assign value
- In your view controller's viewDidLoad method, assign the desired screen name to the ap_screen_name property.
Copiedself.ap_screen_name = @"Custom screen name";
//or
[self setAp_screen_name:@"Custom screen name"];
Copiedself.ap_screen_name = "Custom screen name"
NOTE: For existing screens from the older SDK, use ap_screen_name=NSStringFromClass(self.classForCoder) to maintain the previous tracking. For new screens, provide descriptive names to the ap_screen_name variable.
Control automatic tracking
- You can enable or disable automatic screen tracking using the enableAutomaticScreenTracking and trackAllScreens properties in the AppticsConfig class. By default, automatic screen tracking is enabled.
Copied[[AppticsConfig defaultConfig] enableAutomaticScreenTracking] = YES;
[[AppticsConfig defaultConfig] trackAllScreens] = YES;
CopiedAppticsConfig.defaultConfig().enableAutomaticScreenTracking = true
AppticsConfig.defaultConfig().trackAllScreens = true
The above will ensure that the screens are tracked automatically. You can disable automatic screen tracking as needed.