Menu

Integrated document(macOS)

The SensorsAnalyticsSDK supports macOS starting with v3.0.3

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" :libicucorelibsqlite3 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]; }
CODE

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}];
CODE

Note:

  1. Event name and attribute name are valid variable names if needed and cannot be$ started;
  2. Attribute names are case sensitive, and different events share the same attribute. Even iffoo event includes aaa attribute, Then all subsequent events cannot be used with aaa Only properties that are case-sensitive (e.g. aAa, aaA);
  3. For details about other constraints on event names and attributes, see data format
  4. 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.

Previous
macOS SDK
Next
Basic API Introduction (macOS)
Last modified: 2025-01-02