Getting Started
Installation
Add the following script tag to your HTML:
<script async src="https://cdn.streamform.io/streamform.js"
data-token="YOUR_TOKEN"></script>
Place the script tag in the <head>
section of your HTML for
optimal
performance.
Options
The SDK automatically initializes with your configuration. Available options:
<script async src="https://cdn.streamform.io/streamform.js"
data-token="YOUR_TOKEN"
data-auto-page-view="true"
data-cookie-on-identify="false"
data-skip-patterns="/admin/*,/private/*"
data-mask-patterns="/users/*,/products/*"></script>
Core Methods
Identify Users
Link analytics data to specific users. The userId
parameter is
mandatory:
streamform.identify({
userId: 'user123', // Required
email: 'user@example.com',
name: 'John Doe',
plan: 'premium'
});
The userId
field is required to properly stitch user data across
sessions.
The identify method allows you to:
- Associate future events with a user.
- Add custom user properties.
- Update user information.
Track Events
Track custom events programmatically:
streamform.track('Purchase Completed', {
productId: 'prod_123',
price: 99.99,
currency: 'USD'
});
Page Tracking
Manually track page views:
streamform.page();
Do Not Track
Opt-out of tracking for the current user:
streamform.doNotTrack();
Configuration
URL Patterns
Mask Patterns
Use mask patterns to anonymize URLs containing sensitive information or to group similar URLs together:
<script async src="https://cdn.streamform.io/streamform.js"
data-mask-patterns="/users/*/profile,/products/*/details,/orders/*/"></script>
Example Transformations:
Original URL | Masked URL |
---|---|
/users/123/profile | /users/*/profile |
/products/abc-xyz/details | /products/*/details |
Skip Patterns
Prevent tracking on specific URL patterns:
<script async src="https://cdn.streamform.io/streamform.js"
data-skip-patterns="/admin/*,/account/*,/private/*"></script>
Automatic Page Tracking
Page View Tracking
Enable or disable automatic page view tracking:
<script async src="https://cdn.streamform.io/streamform.js"
data-auto-page-view="true"></script>
Available Data Attributes:
data-sf-event
- Required. The name of the event to trackdata-sf-event-*
- Optional. Any additional properties to track with the event
Trackign with Data Attributes
Track events automatically using HTML data attributes:
<button
data-sf-event="Button Clicked"
data-sf-event-category="cta"
data-sf-event-label="hero">
Click me
</button>
Form Tracking
<form
data-sf-event="Form Submited"
data-sf-event-form="contact">
<input name="email" type="email">
<button type="submit">Submit</button>
</form>
Available Data Attributes
data-sf-event
- Event namedata-sf-event-*
- Custom properties