The SensorsAnalyticsSDK supports macOS starting with v3.0.3
- Before use, please readData model
- SDK update log, can refer to Release Notes
Integrate macOS SDK
CocoaPods method
- In Podfile file add pod 'SensorsAnalyticsSDK', '>=3.0.3'
- Open the terminal and switch to the project directory
- excute pod install or pod update
Note:if excute pod update , the latest version cannot be detected. You can run it firstpod cache clean SensorsAnalyticsSDK to clear local cache.
source code way
- From GitHub get SDK source code
- Import the SensorsAnalyticsSDK directory in the source code into the App project and select Copy items if needed
- Reserve Core、Store、JSBridge three folders and remove the other code
- Project setting "Build Phase" -> Add dependent Libraries in "Link Binary With Libraries" :libicucore、libsqlite3 and libz
Initialize Sensors Analytics macOS SDK
Gets the data receiving address
Get the data receiving address as shown below:
Initialize the SDK and basic configuration
Note: you need toin program entry main thread initialize SDK, Otherwise, some event data may be lost.
Initialize SDK
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application // 初始化配置 SAConfigOptions *options = [[SAConfigOptions alloc] initWithServerURL:<#数据接收地址#> launchOptions:nil]; #ifdef DEBUG // 开启 Log options.enableLog = YES; #endif // 初始化 SDK [SensorsAnalyticsSDK startWithConfigOptions:options]; }
Use Sensors Analytics macOS SDK
Code bury trace event
After the Sensors analytics SDK is successfully initialized, you can usetrack:
和 track:withProperties:
method to track user behavior events and adds custom properties to events. In the case of e-commerce products, you can track a purchase in this way
Code track
UInt64 productId = 123456; NSString *productCatalog = @"Laptop Computer"; BOOL isAddedToFavorites = NO; [[SensorsAnalyticsSDK sharedInstance] track:@"ViewProduct" withProperties:@{@"ProductID" : [NSNumber numberWithUnsignedLong:productId], @"ProductCatalog" : productCatalog, @"IsAddedToFav" : isAddedToFavorites ? @YES : @NO}];
Note:
- Event name and attribute name are valid variable names if needed and cannot be
$
started; - Attribute names are case sensitive, and different events share the same attribute. Even if
foo
event includesaaa
attribute, Then all subsequent events cannot be used withaaa
Only properties that are case-sensitive (e.g. aAa, aaA); - For details about other constraints on event names and attributes, see data format;
- The macOS SDK only supports code burying, not full burying.
User association
The purpose of user association is to uniquely identify users and improve the accuracy of user behavior analysis. At present, we provide simple user association and global user association to support different business scenarios.
Note
Due to the modular architecture, the use of apis in the user-related part of macOS can refer to the iOS SDK, but the use of other interfaces needs to refer to the interfaces in this document.
Set the event public properties
For properties that need to be added for all events, after initializing the SDK, you can use the registerSuperProperties: method to register properties as common properties. For detailed usage documentation, please refer to Basic API Function Introduction.