Menu

Basic API Introduction (C++)

Enable Log Functionality

Enable logging for Sensing Analytics SDK.

""" 开启日志打印 :param enable: 是否开启日志打印,true 开启日志打印;false 关闭日志打印 """ static void EnableLog(bool enable);

Set Common Properties

Set common properties for every event.

""" 设置事件公共属性 :param properties: 要设置的公共属性 """ static void RegisterSuperProperties(const PropertiesNode &properties);

It is recommended to call this method immediately after initializing the SDK to set common properties for all events. If called late, events before setting common properties will not have them.

Clear Common Properties

Clear the set common property content.

static void ClearSuperProperties()

Activate Event

Record installation event, which is called after the first launch following installation. The server can match channel information based on IP address. Multiple calls will trigger multiple times, and there is no single trigger limit within the SDK.

""" 记录激活事件 :param event_name: 激活事件名,建议使用 AppInstall :properties: 激活事件自定义属性 """ static void TrackInstallation(const string &event_name, const PropertiesNode &properties);

Login

Record "Login" and bind the ID before and after login. Subsequently, login_id will be used as distinct_id.

""" 登录 :param login_id: 登录 ID """ static void Login(const string &login_id);

Trigger Custom Event

After SDK initialization, you can call the Track method to track user behavior events and add custom properties to the events:

""" 触发自定义事件 :param event_name: 事件名 """ static void Track(const string &event_name); """ 触发自定义事件 :param event_name: 事件名 :param properties: 事件自定义属性 """ static void Track(const string &event_name, const PropertiesNode &properties);

Set User Property

Update with new value each time

Use the following method to set user properties. When setting the same key multiple times, the value will be overwritten and replaced.

static void ProfileSet(const PropertiesNode &properties); static void ProfileSetString(const string &property_name, const string &str_value); static void ProfileSetNumber(const string &property_name, int number_value); static void ProfileSetNumber(const string &property_name, double number_value); static void ProfileSetBool(const string &property_name, bool bool_value);

Keep Original Properties

For properties that need to be only effective when first set, such as the first recharge amount of a user or the first set nickname, you can use the ProfileSetOnce interface to record them. Unlike the ProfileSet method, if the user property being set already exists, this record will be ignored and the existing data will not be overwritten. If the property does not exist, it will be automatically created:

static void ProfileSetOnce(const PropertiesNode &properties); static void ProfileSetOnceString(const string &property_name, const string &str_value); static void ProfileSetOnceNumber(const string &property_name, int number_value); static void ProfileSetOnceNumber(const string &property_name, double number_value); static void ProfileSetOnceBool(const string &property_name, bool bool_value);

Accumulate Numeric Properties

For some numerical properties, such as consumption amount and user points, we can use ProfileIncrement to accumulate the original values, and Sensors Analytics will automatically calculate and save the accumulated values.

Accumulate operations on a property for a user.

""" 给单个用户属性值进行累加操作,只支持 int 类型 :param property_name: 用户属性 :param number_value: 属性要增加的值 """ static void ProfileIncrement(const string $property_name, int number_value)

Accumulate operations on multiple properties for a user.

""" 给用户的多个属性进行累加操作,支持 int、double 类型 :param properties: 用户属性键值对 """ static void ProfileIncrement(const PropertiesNode &properties);

Append an item to a list property.

For list-type user properties, such as movies users like to watch and restaurants they have reviewed, we can use the ProfileAppend method to append new values:

""" 列表属性追加 :param properties: 用户属性键值对 """ static void ProfileAppend(const PropertiesNode &properties);

Upload data.

Flush.

Call this function actively to pack and upload the SDK's cached tracking data to the server in a fixed number of records (30 records). If the upload fails, the SDK will attempt to re-upload.

static bool Flush();

FlushPart.

Call this function actively to upload the SDK's cached tracking data to the server. Call this function to set the "Number of Records to Upload" and "Whether to Discard Failed Upload Data" parameters.

""" 上报埋点数据 :param part_size: 单次上传事件的条数 :param drop_failed_record: 是否丢弃上传失败的数据 :return: """ static bool FlushPart(size_t part_size, bool drop_failed_record);

Clear the send queue.

Call this function actively to clear the tracked events in the SDK's send queue.

static void ClearQueue();

Active data caching switch.

Introduced in version v0.6, this method allows the active saving of tracked event data in the queue to a local file. The default value is false.

""" 是否允许主动缓存数据 :param enable: 是否开启主动缓存数据 """ static void AppendRecordsToDisk(bool enable);

Cache data in the queue to a local file.

Introduced in version v0.6, this method caches the tracked event data in the queue to a local file and deletes the data in the queue. This function only takes effect when the "Active Data Caching Switch" is set to true.

static void DumpAllRecordsToDisk();

Set Cookie.

Introduced in version v0.7, this method sets the content of the "Cookie" in the https header during event uploading.

""" 设置 Cookie :param cookie: 需要设置的 Cookie :param enable: 是否需要做 encode 编码 """ static void SetCookie(const string &cookie, bool encode);

Get Cookie.

Introduced in version v0.7, this method retrieves the content of the "Cookie" set in the HTTPS header.

""" 获取 Cookie :param decode: 是否需要做 decode 编码 """ static string GetCookie(bool decode);


HTTPS Data Receiving URL

Using HTTPS Data Receiving URL requires curl to be configured with OpenSSL (recommended) or WinSSL (default). The provided compiled curl uses OpenSSL.

In some operating systems, curl may not be able to correctly retrieve the ca-bundle. There are two methods to handle this:

  1. Not adding the ca-bundle and not verifying the server SSL certificate (this will reduce transmission security, recommended for testing only). The specific method is to search for "CURLOPT_SSL_VERIFYPEER" in the sensors_analytics_sdk.cpp file and uncomment the relevant two lines of code;
  2. Includes ca-bundle download link. The specific method is to search for "CURLOPT_CAINFO" in the sensors_analytics_sdk.cpp file, uncomment that line, and specify the path to the certificate file.
Last modified: 2024-12-27