Version compatibility

  • The SDK relies on LuaJIT and currently supports versions Luajit-2.1.0-beta3 and Luajit-2.0.5
  • Currently, the SDK can only be used in Linux environments

  • SDK Depends on Sensors Analytics C SDK(Project libSensorsAnalyticsC.so is a dynamic library based on C SDK v0.2.0 on Linux platform)

1. Lua SDK Instructions for use

Before using, please readdata model introduction.

2. Integrated Sensors analytics SDK

First of all, integrate the dynamic library on the Linux platform (Lua SDK currently only supports Linux), assuming that the name of the dynamic library is libSensorsAnalyticsC.so, there are two ways to get dynamic libraries here:

  1. Use Sensors Analytics C SDK source code sensors_analytics.h and sensors_analytics.c Compile dynamic libraries on Linux platform;
  2. InLua SDK, there is already a dynamic library based on C SDK v0.2.0.

Then integrate the files in the Lua SDK sensors_analytics.lua,import the Lua SDK by require "sensors_analytics" in the Lua file that needs to be buried:

local sensors_analytics = require "sensors_analytics"
CODE

Developers use the Lua SDK to record user behavior data in their applications. The SDK outputs the formatted behavior data to a local disk file in the form of a log file, which the developer needs to analyze through the wizard LogAgent toolsto transfer the log file to the Sensors analytics.LogAgent tool Ensure timeliness and integrity of log transmission.

3. Initialization Sensors analytics SDK

Here we define a table that encapsulates C SDK-related interfaces:

-- 定义一个 table,用于封装 C SDK 相关接口 local _M = new_tab(0, 16) _M.version = "0.0.1" _M.new_tab = new_tab _M.clear_tab = clear_tab _M.FFI_OK = 0 _M.FFI_RESULT_ERROR = 1 _M.FFI_INVALID_PARAMETER_ERROR = 2
CODE

Used in the program

// 初始化 Sensors Analytics 对象 // // @param consumer<in>	日志数据的 “消费” 方式 // // @return SensorsAnalytics 实例. function _M.sa_init(consumer)
CODE

Initialize the example of the strategy analysis, and implement the SDK functions through it. The parameter consumer object is responsible for "consuming" the user behavior log, which is used in the program

// 初始化 Logging Consumer // // @param file_name<in>	日志文件名,例如: /data/logs/http.log // // @return SALoggingConsumer 实例. function _M.sa_init_logging_consumer(file_name)
CODE

initialize SALoggingConsumer instance, It is responsible for exporting the user behavior log to the local disk.

local consumer_res, consumer = sensors_analytics.sa_init_logging_consumer("demo.out") if consumer_res ~= SA_FFI_OK then print("Failed to initialize the consumer.") return end local sa_res, sa = sensors_analytics.sa_init(consumer) if sa_res ~= SA_FFI_OK then print("Failed to initialize the SDK.") return end // ... 使用神策分析进行各种操作 sensors_analytics.sa_flush(sa) sensors_analytics.sa_free(sa) 
CODE