The SegmentStream SDK script sends additional GA4 events that act as user engagement signals. It also improves the attribution of users who begin browsing your website through in-app browsers that open when ads are clicked within apps, such as Instagram, LinkedIn, etc.
Installing the SDK via GTM
Create a new tag
In Google Tag Manager, go to Tags and click New.
Configure the tag
Name the tag SegmentStream SDK and choose the Custom HTML tag type.
Add the SDK code
Enter the following code. Replace ID PROVIDED BY MANAGER with the ID provided by your SegmentStream account manager.<script>(function(){var s=window.segmentstream=window.segmentstream||{};
s._q=s._q||[];['init','conversion'].forEach(function(m){
s[m]=function(){s._q.push([m,Array.prototype.slice.call(arguments)])}})})();</script>
<script async src="https://cdn.segmentstream.com/js/segmentstream.min.js">
</script>
<script>segmentstream.init("ID PROVIDED BY MANAGER");</script>
Set firing options
Expand Advanced Settings and select Once per page in Tag firing options.
Add a trigger
Choose All Pages in the Firing Triggers option.
Tracking non_idle events
The non_idle event measures active user engagement time on the page.
Create a trigger
Go to Triggers and click New.
Configure the trigger
Name the trigger Event - non_idle and choose the Custom Event trigger type.
Set the event name
Enter non_idle in the Event name field.
Create a data layer variable
Go to Variables and click New.
Configure the variable
Name the variable nonIdleTimeElapsed and select the Data Layer Variable type.
Set the variable name
Enter nonIdleTimeElapsed in the Data Layer Variable Name field.
Create the GA4 event tag
Go to Tags, click New, and choose the GA4 Event tag type.
Configure the GA4 event
- Enter the Measurement ID used by your Google Tag.
- Set Event - non_idle as the trigger.
- Enter the settings:
- Event Name:
non_idle
- Event Parameters:
value = {{nonIdleTimeElapsed}}
The event name must be exactly non_idle (case-sensitive), and the event parameter name must be exactly value. Any other variations will not be recognised by the system.

Detecting bots
The bot_detected event identifies non-human traffic.
Create a trigger
Go to Triggers and click New.
Configure the trigger
Name the trigger Event - bot_detected and choose the Custom Event trigger type.
Set the event name
Enter bot_detected in the Event name field.
Create the is_bot variable
Go to Variables, click New, name the variable is_bot, and select the Data Layer Variable type.
Set the variable name
Enter is_bot in the Data Layer Variable Name field.
Create the GA4 event tag
Go to Tags, click New, and choose the GA4 Event tag type.
Configure the GA4 event
- Enter the Measurement ID used by your Google Tag.
- Set Event - bot_detected as the trigger.
- Enter the settings:
- Event Name:
bot_detected
- User Properties:
is_bot = {{is_bot}}
The event name must be exactly bot_detected (case-sensitive), and the user property name must be exactly is_bot. Any other variations will not be recognised by the system.

Aggregated conversions measurement
The SegmentStream SDK supports conversion tracking that complies with modern privacy regulations. It enables attribution and performance measurement even for users who have not provided consent for cookies. This is achieved through an aggregated tracking method that does not rely on cookies or any personally identifiable information (PII).
Implementation through GTM
Create a new tag
In Google Tag Manager, go to Tags, click New, name the tag SegmentStream Conversion Tracking, and choose the Custom HTML tag type.
Add the conversion code
In the HTML block, insert the appropriate code for your conversion type: Purchase (with order ID)
Lead (no order ID)
Signup (with value)
Replace ORDER_ID and ORDER_VALUE with the variables used in your GA4 conversion tag.<script>
segmentstream.conversion({
id: 'ORDER_ID',
type: 'purchase',
value: ORDER_VALUE
});
</script>
<script>
segmentstream.conversion({
type: 'lead'
});
</script>
<script>
segmentstream.conversion({
type: 'signup',
value: ORDER_VALUE
});
</script>

Set the trigger
Set the trigger for this tag to match the trigger used by your GA4 conversion tag.
Configure tag sequencing
In Tag Sequencing, make sure the SegmentStream SDK tag fires before this tag.
Save and publish
Save and publish the changes.
Implementation via SDK
You can trigger a conversion directly using the SDK method:
segmentstream.conversion({
id: 'ORDER_ID', // Optional: unique identifier for the conversion
type: 'purchase', // Required: event type (e.g., 'purchase', 'lead', 'signup')
value: ORDER_VALUE // Optional: numeric value of the conversion
});
Examples:
segmentstream.conversion({
id: 'ORD-12345',
type: 'purchase',
value: 199.99
});
This function should be called on the conversion confirmation page (e.g. the order success or thank-you page), after the SegmentStream SDK is initialised.
Sending lead data to your CRM
When sending lead data from your website to your CRM, pass the user identifier provided by the SegmentStream SDK instead of using the _ga cookie value:
window.segmentstream.anonymousId()
- If the user has consented to cookies, this method returns the
_ga cookie value.
- If the user has not consented, it returns a generated anonymous ID (instead of
null).
This approach ensures that SegmentStream’s aggregated attribution works for both consented and non-consented users.
How to implement:
- If your CRM currently receives the
_ga cookie value, replace it with window.segmentstream.anonymousId().
- If replacement is not possible, send the
anonymousId() value to a separate field in your CRM.
- On the same page where the lead is sent to the CRM, call
window.segmentstream.conversion().
Calling the conversion method on a different page (for example, a redirect page after the lead is sent) will not work for aggregated conversion attribution. The call must happen on the same page where the lead is submitted.
// Send data to the CRM
const clientId = window.segmentstream.anonymousId();
sendLeadToCRM({
name: leadName,
email: leadEmail,
clientId: clientId
});
// Send data to SegmentStream
window.segmentstream.conversion();
Configuring SDK settings
By default, the SegmentStream SDK loads all available modules. If you want to prevent specific modules from loading, configure the settings script before initialising the SDK.
Available modules:
| Module | Description |
|---|
collect_activity | Sends the non_idle engagement event. |
click_id_propagation | Attributes users browsing via in-app browsers. |
enable_bot_detection | Identifies bot traffic. |
cookieless_pings | Sends pings without personally identifiable information. |
preconsent_storage | Stores attribution data in localStorage without PII. |
<script>(function(){var s=window.segmentstream=window.segmentstream||{};
s._q=s._q||[];['init','conversion'].forEach(function(m){
s[m]=function(){s._q.push([m,Array.prototype.slice.call(arguments)])}})})();</script>
<script>
window.segmentstream_sdk_settings = {
collect_activity: true,
click_id_propagation: true,
enable_bot_detection: true,
cookieless_pings: true,
preconsent_storage: true
};
</script>
<script async src="https://cdn.segmentstream.com/js/segmentstream.min.js">
</script>
<script>segmentstream.init("ID PROVIDED BY MANAGER");</script>