Skip to main content
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

1

Create a new tag

In Google Tag Manager, go to Tags and click New.GTM Tags page with New button
2

Configure the tag

Name the tag SegmentStream SDK and choose the Custom HTML tag type.Selecting Custom HTML tag type
3

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>
4

Set firing options

Expand Advanced Settings and select Once per page in Tag firing options.
5

Add a trigger

Choose All Pages in the Firing Triggers option.SDK tag with All Pages trigger

Tracking non_idle events

The non_idle event measures active user engagement time on the page.
1

Create a trigger

Go to Triggers and click New.GTM Triggers page with New button
2

Configure the trigger

Name the trigger Event - non_idle and choose the Custom Event trigger type.Selecting Custom Event trigger type
3

Set the event name

Enter non_idle in the Event name field.non_idle event name configured
4

Create a data layer variable

Go to Variables and click New.GTM Variables page with New button
5

Configure the variable

Name the variable nonIdleTimeElapsed and select the Data Layer Variable type.Selecting Data Layer Variable type
6

Set the variable name

Enter nonIdleTimeElapsed in the Data Layer Variable Name field.nonIdleTimeElapsed variable configured
7

Create the GA4 event tag

Go to Tags, click New, and choose the GA4 Event tag type.Selecting GA4 Event tag type
8

Configure the GA4 event

  1. Enter the Measurement ID used by your Google Tag.
  2. Set Event - non_idle as the trigger.
  3. 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.
non_idle GA4 event tag configured

Detecting bots

The bot_detected event identifies non-human traffic.
1

Create a trigger

Go to Triggers and click New.
2

Configure the trigger

Name the trigger Event - bot_detected and choose the Custom Event trigger type.bot_detected Custom Event trigger
3

Set the event name

Enter bot_detected in the Event name field.bot_detected event name configured
4

Create the is_bot variable

Go to Variables, click New, name the variable is_bot, and select the Data Layer Variable type.Selecting Data Layer Variable for is_bot
5

Set the variable name

Enter is_bot in the Data Layer Variable Name field.is_bot variable configured
6

Create the GA4 event tag

Go to Tags, click New, and choose the GA4 Event tag type.
7

Configure the GA4 event

  1. Enter the Measurement ID used by your Google Tag.
  2. Set Event - bot_detected as the trigger.
  3. 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.
bot_detected GA4 event tag configured

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

1

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.
2

Add the conversion code

In the HTML block, insert the appropriate code for your conversion type:
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>
Conversion tracking tag configuration
3

Set the trigger

Set the trigger for this tag to match the trigger used by your GA4 conversion tag.
4

Configure tag sequencing

In Tag Sequencing, make sure the SegmentStream SDK tag fires before this tag.
5

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:
  1. If your CRM currently receives the _ga cookie value, replace it with window.segmentstream.anonymousId().
  2. If replacement is not possible, send the anonymousId() value to a separate field in your CRM.
  3. 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:
ModuleDescription
collect_activitySends the non_idle engagement event.
click_id_propagationAttributes users browsing via in-app browsers.
enable_bot_detectionIdentifies bot traffic.
cookieless_pingsSends pings without personally identifiable information.
preconsent_storageStores 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>