Tracking SDK
Overview
The Feature Platform Tracking SDK is a lightweight, asynchronous JavaScript library designed to capture user interactions on your website or application. It provides a simple and powerful way to send event data to the Feature Platform, enabling you to understand user behavior, build powerful analytics, and trigger real-time campaigns.
Key Features
- Segment-compatible API: If you've used Segment before, you'll feel right at home. Our API is designed for a seamless and familiar integration experience.
- Asynchronous and Non-blocking: The SDK is designed to load and operate without impacting your site's performance. It won't slow down your page load times or interfere with the user experience.
- Client-side and Server-side Event Forwarding: Our robust solution combines client-side tracking with server-side event forwarding, making it resistant to ad-blockers and ensuring complete data capture.
Quick Implementation
Include the Feature SDK in your website or application by adding the following script tag to the <head> of your HTML
file:
<!-- Latest version -->
<script src="https://cdn.feature.io/latest/feature.min.js"></script>
<!-- Specific version (recommended for production) -->
<script src="https://cdn.feature.io/v0.0.17/feature.min.js"></script>
<!-- With Subresource Integrity (SRI) for security -->
<script src="https://cdn.feature.io/v0.0.17/feature.min.js"
integrity="sha384-[hash-will-be-provided-in-releases]"
crossorigin="anonymous"></script>
After including the script, Feature will be available globally:
<script>
const feature = new Feature({
serverUrl: 'https://feature.example.com',
publicApiKey: 'your-public-api-key',
});
feature.track('page-view', { page: 'home' });
</script>
You can now initialize the client with your Feature instance URL and public API key:
import Feature from '@feature/browser-sdk';
const feature = new Feature({
serverUrl: 'https://feature.example.com',
publicApiKey: 'your-public-api-key',
});
The client is built on top of Analytics and supports all of its methods.
For example, you can identify a user like this:
feature.identify('user-id', {
email: 'test@example.com',
});
And track an event like this:
feature.track('test-event', {
test: 'test-value',
});
Or to record a page view:
feature.page();
Replace your-public-api-key with your actual Feature Platform tenant ID.
Sending Events
Once the SDK is installed, you can start sending events using the feature.track() method. This method allows you to
record any user action, along with its associated properties.
Here's an example of how to track a "Video Watched" event:
feature.track("Video Watched", {
videoId: "123",
watchTime: 90
});
Event Payload Structure
The track method sends an event payload to the Feature Platform. Here is an example of a standard event payload:
{
"event": "Video Watched",
"properties": {
"videoId": "123",
"watchTime": 90
},
"userId": "user-456",
"anonymousId": "anon-789"
}
event(string, required): The name of the event you're tracking.properties(object, required): A dictionary of properties for the event.userId(string, optional): The user's unique identifier in your system.anonymousId(string, optional): A unique identifier for anonymous users.
Advanced: Server-Side Tracking
For maximum reliability, especially in mobile applications or to bypass ad-blockers, we recommend implementing server-side tracking.
The Feature Platform supports server-side event forwarding through a standard backend-to-backend API. This ensures that you can capture every event, providing a complete and accurate picture of your user's journey. For more information, please refer to our API documentation.