TengenceTengence
Product docs

Integrate behavioral data

Collect web events into a Tengence dataset with the JavaScript SDK or NPM package. Configure event types, global properties and verify ingestion.

Behavioral data integration collects events from a website or web application into a Tengence dataset. You create the integration app and dataset in Data Integration; Tengence Insight only binds to the finished dataset for analysis.

Two integration paths are supported: a JavaScript script for any page, and an NPM package for React, Vue or other bundlers. Both use the same event model, batching and retry behavior.

When to use behavioral data integration

  • You need page views, clicks, scroll depth, form starts, form submits or custom product events.
  • You want Tengence Insight to analyze traffic and conversion without building your own event pipeline.
  • You need a device ID, session handling and retry logic without writing them yourself.
  • You prefer a front-end SDK over a server-side API push.

Create the behavioral app and dataset

  1. Open Data Integration → Apps and select + New App. Choose Free and select Create.
  2. On the app detail page, select Configure Data Source.
  3. Select Behavioral data.
  4. Select the dataset to receive events, or create one in the same flow.
  5. Choose the Data types to collect: All tracking events, Behavior events, Performance events and Error events. Leave All tracking events on if you want page views, clicks, scrolls and forms out of the box.
  6. Keep Auto-start app on, then select Save.
  7. On the app detail page, copy the Behavior event push URL and API Key.
Behavioral data integration app detail with event push URL, API key and SDK collection settings
Behavioral data integration app detail with event push URL, API key and SDK collection settings

Authentication

The SDK accepts three credential models:

Model Use when How it works
apiKey Server-rendered page or a trusted internal tool The SDK sends the API key as the Bearer credential.
authUrl Public website with a server that can issue short-lived tokens The SDK requests accessToken and accessExpAt from your endpoint and refreshes before expiry.
setToken You already have a token from your own auth service Inject the access token into the SDK before events are sent.

For a public website, use authUrl. Do not embed the long-lived API key in page source. A minimal token endpoint can exchange the key on the server and return only the short-lived token.

JavaScript integration

Add the fixed-version script to the page. Pin the version so a release cannot change your event shape unexpectedly.

<!-- Production: pin the exact version; @latest is only for testing -->
<script src="https://static.tengence.com/track/tengence-track-sdk@1.3.1.js"></script>
<script>
  const client = window.TrackSDK.init({
    apiKey: "sk-your-api-key", // server-side page only
    // authUrl: "https://your-site.example/api/track-token", // preferred for public sites
  });
</script>

Send a custom event:

client.track("product_view", {
  product_id: "P1001",
  product_name: "Aurora Lounge Chair",
  category: "Seating",
  price: 1299,
  currency: "CNY"
});

Register properties that should be attached to every event, such as plan, locale or account tier:

client.registerGlobalProperties({
  plan: "free",
  locale: "en-US",
  account_type: "consumer"
});

Bind the logged-in user ID after sign-in so events can be joined to your own user records:

window.trackMonitor.bindUser("user_12345");

Flush pending events when the page is about to close or when you need immediate delivery:

await client.flush();

What the SDK collects automatically

Data type Automatic events Can you turn it off?
All tracking events Page views, clicks, scroll depth, form start, form submit, element exposure Yes, deselect All tracking events or disable individual collectors in SDK config.
Behavior events Custom events sent with track() No; custom calls are explicit.
Performance events Page load timing, LCP, CLS, INP, resource timing Yes, deselect Performance events.
Error events JavaScript errors, resource errors, unhandled promise rejections, HTTP errors Yes, deselect Error events.

Default batching sends when 5 seconds pass or 100 events accumulate, whichever comes first. A failed batch stays in the local queue and is retried with exponential backoff. The SDK drops an event over 64 KB and keeps at most 2,000 events in the queue.

Behavioral data JavaScript integration drawer showing SDK script, bindUser and authentication guidance
Behavioral data JavaScript integration drawer showing SDK script, bindUser and authentication guidance

NPM integration

Install the package in your application:

npm install @tengence/track-sdk-web@^1.3.1

Initialize it once at application startup:

import init from "@tengence/track-sdk-web";

const client = init({
  apiKey: "sk-your-api-key",
  // authUrl: "https://your-site.example/api/track-token",
});

React example

import { useEffect } from "react";
import init from "@tengence/track-sdk-web";

let client;

export function useAnalytics() {
  useEffect(() => {
    if (!client) {
      client = init({ authUrl: "/api/track-token" });
    }
    client.track("page_view", { page: "home" });
  }, []);
}

Vue example

import { onMounted } from "vue";
import init from "@tengence/track-sdk-web";

const client = init({ authUrl: "/api/track-token" });

onMounted(() => {
  client.track("page_view", { page: "home" });
});

Event and field reference

Field Required Description
event_id Yes for manual HTTP Unique event ID. The SDK generates it when omitted.
platform Yes web, h5 or another platform label.
data_type Yes behavior, auto, performance or error.
event_type Yes Event name, for example page_view, click, product_view.
event_time Yes Event time in milliseconds as a string.
page_url Yes Full URL of the page where the event happened.
user_id No Logged-in user ID. Set it with bindUser.
device_id No Stable device ID generated and stored by the SDK.
spm No Your internal page or element tracking code.
event_detail No JSON object or JSON string with event-specific properties.
register_properties No JSON string of global properties; only fields registered with registerGlobalProperties are accepted.

Manual HTTP reporting without the SDK

If you cannot use the SDK, send events to the same endpoint. The SDK is recommended because it handles batching, device IDs, retries and token refresh.

curl -X POST "https://api.tengence.com/v1/push/event" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "event_id": "evt_1001",
    "platform": "web",
    "data_type": "behavior",
    "event_type": "product_view",
    "event_time": "1796000000000",
    "page_url": "https://www.example.com/products/P1001",
    "event_detail": "{\"product_id\":\"P1001\",\"price\":1299}"
  }' 

The event detail and register properties accept up to 50 keys. Key names are limited to 64 characters and a single value to 1 KB. Basic types only; nested objects should be serialized as a JSON string. Events over the limit still arrive, but excess keys are dropped.

Verify events

  1. Open Data Center → Datasets and select the behavioral dataset.
  2. Check Record count after a few minutes of traffic.
  3. Open Preview and confirm event_type, page_url and custom fields look correct.
  4. Bind the dataset to a Tengence Insight application and open the site analysis report. The binding flow is in the Tengence Insight guide.

Billing

Behavioral events consume dataset storage in your package. The SDK itself is free to embed; Search, GEO, Recommendation and Insight usage is metered by the product that reads the dataset.

FAQ

Do I need to push events myself?

No. After you integrate the SDK, it collects and sends the configured event types. You only call track() for custom events that are not covered by automatic collection.

Should I use the API key or authUrl in a public page?

Use authUrl. The API key is a server-side secret. The token endpoint should exchange it for a short-lived token and return only that token.

Why are my events not appearing?

Check the app run status, the SDK initialization credential, the browser network tab for rejected requests, and the dataset record count. If the app is stopped, events are rejected.

How long does the SDK wait before sending?

By default, 5 seconds or 100 events, whichever comes first. You can lower the interval or call flush() for immediate delivery.

Can I send events from a mobile app?

The JavaScript SDK targets web and H5. For native apps, send the same event schema over HTTPS or use a platform SDK if one is available for your stack.

On this page
Integrate behavioral data - Data Integration | Tengence Docs