DataFinder provides you with Node.js SDK, which is convenient for you to perform event tracking on some non-web pages, such as Chrome plugins for event tracking and other scenarios. This article provides you with a hands-on guide to Node.js SDK integration.
Before starting the integration, you first need to have an application in the group. Before integrating the SDK, you need to obtain the appid, app key, schema and other information of the corresponding application.
In the privatization scenario, you can view your appid, app key, and schema in "Project Center" - > "Project Management" - > "Project Details" - > "Access to the application" - > "Application ID". For details, please refer to Project Details and Application List.
In the private deployment scenario, you need to obtain the data upload address for your own planning and configuration when deploying a private environment. If you do not know this address, please contact your project manager or customer success manager.
npm i @datarangers/sdk-node npm i @datarangers/node-plugin-http
import { DataRangersSDK } from "@datarangers/sdk-node"; import { httpPlugin } from '@datarangers/node-plugin-http'; const sdk = new DataRangersSDK({ app_id: 1234, //Pass the appid of the applied item, which must be a number. logLevel: "verbose", //Turn on local chronology printing, the default value is silent });
Parameter | Configuration instructions |
|---|---|
app_id | Configure the app ID that is generated when you create an app on the DataFinder, see the Get Appid section above for details. |
logLevel | To configure whether to enable local log printing, the enumeration values are as follows.
|
After initializing the SDK, you need to set the data reporting address before you can report event tracking.
sdk.use( httpPlugin( { channel_domain: "https://***.****.com" //Set up the reporting domain name. In a privatization environment, you need to contact the project manager to obtain the data reporting address. } ) );
When you need to set the login ID, or when there are global public properties, you can use config for configuration.
sdk.config({ user: { user_unique_id: "xxx", //Set the global user uuid }, header: { os_name: 'xxx', //Set and modify public properties }, custom: { key: 123 //Set custom public properties } });
//event tracking sdk.collect( "event_1", //event tracking name { event_param_a: 123, //event tracking properties } );
Batch report event tracking, that is, pass in a buried array.
//Bulk reporting event tracking sdk.collect([ { name: "event_2", params: { event_param_b: 234, }, }, { name: "event_3", params: { event_param_c: 567, }, }, ]);