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.
    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>
  1. Expand the Advanced Settings and select Once per page in the Tag firing options.
  1. Choose All Pages in the Firing Triggers option.
    1. 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>
      If you are tracking an event without an ID or value, such as a lead, use the following code:
      html
      <script>segmentstream.conversion();</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.

Sending Lead Data to your CRM

When sending lead data from your website to your CRM, you should also send the user identifier provided by the SegmentStream SDK.
Instead of using the _ga cookie value, pass the value returned by the following method:
javascript
window.segmentstream.anonymousId()
  • If the user has consented to cookies, this method will return the _ga cookie value.
  • If the user has not consented, it will return 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. Replace the _ga cookie
    1. If your CRM currently receives the _ga cookie value, replace it with window.segmentstream.anonymousId().
  1. If replacement is not possible
    1. Send the anonymousId() value to a separate field in your CRM.
  1. Trigger the Conversion Event on the Same Page
    1. On the same page where the lead is sent to the CRM, you must also 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.
  1. Usage Example
    1. javascript
      // code that sends data to the CRM const clientId = window.segmentstream.anonymousId(); sendLeadToCRM({ name: leadName, email: leadEmail, clientId: clientId }); // code that sends data to SegmentStream window.segmentstream.conversion();
This ensures consistent attribution coverage while remaining compliant with privacy regulations.

Special Cases in Conversion Tracking

The segmentstream.conversion() method supports flexible parameter usage for different tracking scenarios:
  1. Multiple Conversion Types
      • If you want to track several different types of conversions, use the optional third parameter to specify the conversion name:
        • javascript
          segmentstream.conversion('ORDER_ID', ORDER_VALUE, 'CONVERSION_NAME');
  1. No Parameters Available
      • If your conversion doesn’t have an order ID, value, or name, you can call the method without any arguments:
        • javascript
          segmentstream.conversion();
  1. Skipping Parameters
      • If a specific parameter is missing but the next one exists (e.g., no order ID but there is a value), pass null for the missing parameters:
        • javascript
          segmentstream.conversion(null, ORDER_VALUE);
This flexibility ensures you can accurately track conversions regardless of the available data structure on your website.

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>