- Want to get user behavior data?
- Want to easily view graphs of user behavior?
- Want to efficiently manage App operations?
Yes, let me show you App statistics. Here I use professional, lightweight JAnalytics. This article is divided into two parts: code examples & Tips section and console chart viewing section.
Code examples & use tips
integration
- Download JAnalytics SDK
- add
Lib
All files in the folder go to Xcode Project - Add related framework dependencies: UIKit.framework SystemConfiguration.framework CoreTelephony.framework CoreGraphics.framework Security.framework Foundation.framework CoreLocation.framework CoreFoundation.framework CFNetwork.framework libz.tbd libresolv.tbd
To initialize the SDK
#import "JANALYTICSService.h"Copy the code
In application: didFinishLaunchingWithOptions add the following code:
Code sample
JANALYTICSLaunchConfig * config = [[JANALYTICSLaunchConfig alloc] init];
config.appKey = @"your appkey";
config.channel = @"channel";
[JANALYTICSService setupWithConfig:config];Copy the code
The appKey parameter requires you to register an account in the polar console and create an App project to obtain it.
Page flow statistics
+startLogPageView
: Starts counting a page, which can be written to the ViewControlerviewDidAppear:
+stopLogPageView
The page can be written to the ViewControlerviewDidDisappear:
Code sample
- (void)viewDidAppear:(BOOL)animated {
[JANALYTICSService startLogPageView:@" page name"];
}
- (void)viewDidDisappear:(BOOL)animated {
[JANALYTICSService stopLogPageView:@" page name"];
}Copy the code
Use skills
The above method needs to be written in all controllers. It is recommended to add the following code to your own UIViewController base class, BaseViewController, or to add a Category to UIViewController. You can count all existing or new pages by writing them once, which reduces the amount of code and does not worry about missing pages:
- (void)viewDidAppear:(BOOL)animated {
[JANALYTICSService startLogPageView:NSStringFromClass([self class])];
}
- (void)viewDidDisappear:(BOOL)animated {
[JANALYTICSService stopLogPageView:NSStringFromClass([self class])];
}Copy the code
Based on the above code, you can also define a separate PageNameFromClass method that retrieves the class into a specific page name
Geographic statistics
+setLatitude:longitude: : reports geographic location information
Code sample
[JANALYTICSService setLatitude:116.46 longitude:39.92];Copy the code
Crash log statistics
+ crashLogON: open collecting Suggestions on the application of the crash log: didFinishLaunchingWithOptions invoke this method.
Code sample
[JANALYTICSService setLatitude:116.46 longitude:39.92];Copy the code
Event statistics
+eventRecord collects statistics of various events by passing in different event models. Currently, it supports the following events: registration, login, purchase, browse, count, and calculate.
Code sample
[JANALYTICSService eventRecord:event];Copy the code
The events need to be created for each event. For example, registration events:
JANALYTICSRegisterEvent * event = [[JANALYTICSRegisterEvent alloc] init];
event.success = YES;// Check whether the registration is successful
event.method = @" Registration method";
event.extra = @{@" Custom key1":@" Custom value1"};
[JANALYTICSService eventRecord:event];Copy the code
See here for the creation of various events
Console chart view
You can view the statistical chart of various data in App on the statistics page of the console.
- Free features: including push statistics, user statistics, participation retention, error analysis, event statistics, page statistics, etc., is also enough to meet the statistical needs.
- VIP: Provides advanced functions such as terminal statistics, ranking statistics, and user portraits.
In general, the data will be refreshed every hour after the App calls the corresponding interface. In addition, each statistic contains a variety of different functions, you can try it in turn.