Guide to using custom segmentation using Google Tag Manager

Google Tag Manager can make segmentation easy for you to add on specific events. Rather than adding or making changes to the codebase, you can add specific tags to events based on your use case.

Using Javascript API

Regular Segmentation

You can use the below code snippet to be added on a button click, image click or form submission. This code ensures that you can place them into a tag and then trigger it on a specific event.

window._peq.push(["add-to-segment", "segmentName"]);

You have to ensure that the segment is already created in the dashboard. For creating Segments, please navigate to Audience > Segments in PushEngage Dashboard. Copy the same segment name and use it in the code. For example, if your segment is called ‘Form Submitted,’ the code would look like this –

window._peq.push(["add-to-segment", "Form Submitted"]);

Dynamic Segmentation

Dynamic segmentation is different from regular segmentation. Here you can specify the number of days you want the subscriber to remain in the segment, after the defined duration it will be automatically removed.

<code>var days = 5; window._peq.push(["add-to-dynamic-segment", "segmentName", days]); </code>

You can refer to more details about dynamic segmentation here.

Now, we will understand how to add this segmentation code to Google Tag Manager.

Adding the code to the Tag

You can open the container and navigate to the Tags section > Click on the New Tag button in the right corner.

Add the name of the Tag > Configure with Custom HTML and add the Javascript code to the tag within <script> tags.

Adding the Trigger to the Tag

Create a New Trigger and configure the Trigger based on your use case. You can use the Page URL pattern or an element ID.

There are various methods to use Trigger you can use an existing Trigger available or the one mentioned in the list.

Below is an example to use the Page URL Triggers –


Once you have added the Tags and Triggers, you can review and publish them changes.

That’s all we need to do to set up segments using Google Tag Manager. Once the subscribers become a part of this segment, you can start targeting them with contextual campaigns.

If in case you run into any issues, please feel free to contact us by clicking here. Our support team would be able to help you

Still stuck? How can we help?
Last updated on September 26th, 2023

Engage and Retain Visitors AfterThey’ve Left Your Website

Increase the value of every web visit with Push Notifications that are hard to miss.

  • Forever Free Plan
  • Easy Setup
  • 5 Star Support