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.
- Inside your Google Tag Manager go to Tags, and click New:
- Name the tag SegmentStream SDK, and choose the Custom HTML tag type:
- Enter the following code that will be provided by your SegmentStream account manager, and choose All Pages in the Firing Triggers option:
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>
Tracking non_idle events
- Go to Triggers, and click New:
- Name the trigger as it suits you, for example Event - non_idle, and choose the Custom Event trigger type:
- 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:
- In order to collect the non-idle time, we have to create a new variable. Go to Variables, click New:
- Name the variable as nonIdleTimeElapsed, and select the Data Layer Variable type:
- Enter nonIdleTimeElapsed in the Data Layer Variable Name field, your variable should look like this:
- Go to Tags, click New:
- Choose GA4 Event tag type.
- 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 should be exactly value
. Any other variations will not be recognised by the system.Detecting Bots
- Go to Triggers, and click New:
- Name the trigger as it suits you, for example Event - bot_detected, and choose the Custom Event trigger type:
- 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:
- Go to Variables, click New:
- Name the variable as is_bot, and select the Data Layer Variable type:
- Enter is_bot in the Data Layer Variable Name field, your variable should look like this:
- Go to Tags, click New:
- Choose GA4 Event tag type.
- 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 should be exactly is_bot
. Any other variations will not be recognised by the system.- 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
- Inside your Google Tag Manager go to Tags, and click New:
- Name the tag SegmentStream Conversion Tracking, and choose the Custom HTML tag type.
- In the HTML block, insert the code below. Replace
ORDER_ID
andORDER_VALUE
with the variables used in your GA4 Purchase tag fortransaction_id
andvalue
.
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>
- Set the trigger for this tag to match the trigger used by your GA4 Purchase tag.
- In Tag Sequencing, make sure the SegmentStream SDK tag fires before this tag.
- Save and Publish the changes.
Implementation via SDK
You can manually trigger a conversion using the following method:
javascriptsegmentstream.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 thenon_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>