logo
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.
Below is the guide for implementing the script and the GA4 event.
  1. Inside your Google Tag Manager go to Tags, and click New:
    1. Image without caption
  1. Name the tag SegmentStream SDK, and choose the Custom HTML tag type:
    1. Image without caption
  1. Enter the following code that will be provided by your SegmentStream account manager, and choose All Pages in the Firing Triggers option:
    1. html
      <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>
      Image without caption

Tracking non_idle events

  1. Go to Triggers, and click New:
    1. Image without caption
  1. Name the trigger as it suits you, for example Event - non_idle, and choose the Custom Event trigger type:
    1. Image without caption
  1. Enter non_idle in the Event name field, which is the name of the event pushed into the dataLayer by the SDK script. It should look like this:
    1. Image without caption
  1. In order to collect the non-idle time, we have to create a new variable. Go to Variables, click New:
    1. Image without caption
  1. Name the variable as nonIdleTimeElapsed, and select the Data Layer Variable type:
    1. Image without caption
  1. Enter nonIdleTimeElapsed in the Data Layer Variable Name field, your variable should look like this:
    1. Image without caption
  1. Go to Tags, click New:
    1. Image without caption
  1. Choose GA4 Event tag type.
    1. Image without caption
  1. Enter the Measurement ID used by your Google Tag.
  1. Set Event - non_idle as the trigger.
  1. 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 should be exactly value. Any other variations will not be recognised by the system.
      Image without caption

Detecting Bots

  1. Go to Triggers, and click New:
    1. Image without caption
  1. Name the trigger as it suits you, for example Event - bot_detected, and choose the Custom Event trigger type:
    1. Image without caption
  1. Enter bot_detected in the Event name field, which is the name of the event pushed into the dataLayer by the SDK script. It should look like this:
    1. Image without caption
  1. Go to Variables, click New:
    1. Image without caption
  1. Name the variable as is_bot, and select the Data Layer Variable type:
    1. Image without caption
  1. Enter is_bot in the Data Layer Variable Name field, your variable should look like this:
    1. Image without caption
  1. Go to Tags, click New:
    1. Image without caption
  1. Choose GA4 Event tag type.
    1. Image without caption
  1. Enter the Measurement ID used by your Google Tag.
  1. Set Event - bot_detected as the trigger.
  1. 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 should be exactly is_bot. Any other variations will not be recognised by the system.
      Image without caption
  1. Optional - Create an is_bot user level dimension by following our guide - Additional GA4 settings.

Aggregated Conversions Measurement

The SegmentStream SDK supports conversion tracking in a way that complies with modern privacy regulations. It enables attribution and performance measurement even for users who haven’t 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. Inside your Google Tag Manager go to Tags, and click New:
    1. Image without caption
  1. Name the tag SegmentStream Conversion Tracking, and choose the Custom HTML tag type.
  1. In the HTML block, insert the code below. Replace ORDER_ID and ORDER_VALUE with the variables used in your GA4 Purchase tag for transaction_id and value.
    1. Image without caption
      🔒
      Note: ORDER_ID is used only on the client side to avoid duplicate conversions and is not sent to the server.
      html
      <script>segmentstream.conversion('ORDER_ID', ORDER_VALUE);</script>
  1. Set the trigger for this tag to match the trigger used by your GA4 Purchase tag.
  1. In Tag Sequencing, make sure the SegmentStream SDK tag fires before this tag.
    1. Image without caption
  1. Save and Publish the changes.

Implementation via SDK

You can manually trigger a conversion using the following method:
javascript
segmentstream.conversion('ORDER_ID', ORDER_VALUE);
  • Replace 'ORDER_ID' with a unique identifier for the conversion event (e.g., an order ID).
  • Replace ORDER_VALUE with the corresponding numeric value.
🔒
Note: ORDER_ID is used only on the client side to avoid duplicate conversions and is not sent to the server.
This function should be added on the conversion confirmation page (e.g., the order success or thank-you page), after the SegmentStream SDK is initialised.

Configuring SegmentStream SDK Settings

By default, the SegmentStream SDK loads all available modules on your website. If you want to prevent specific modules from loading, you need to configure the settings script before initialising the SDK script.
This configuration is only necessary if you want to disable specific modules. Without it, all modules will be loaded automatically.
You can control the following modules:
  • Toggle the collect_activity module (used for sending the non_idle event).
  • Toggle the click_id_propagation module (used for attributing users browsing via in-app browsers).
  • Toggle the enable_bot_detection module (used for identifying bots).
Example script:
html
<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, // activity event tracking click_id_propagation: true, // attribution improvement enable_bot_detection: true // bot detection }; </script> <script async src="https://cdn.segmentstream.com/js/segmentstream.min.js"> </script> <script>segmentstream.init("ID PROVIDED BY MANAGER");</script>