To segment users using the Javascript API, firstly, please follow the first step of the Getting Started article by clicking here.
You would also want to refer to our full Javascript API, with a detailed description on our API documentation page.
Now, please find below some tips for segmentation of users using the Javascript API.
The specific API call we'll be using is Add Subscriber to a Segment. Here's an example to show you how this API works:
Suppose the user has visited a portion of your site, say the Checkout page, then the visitor (if s/he is a subscriber already), will be added to the segment named “checkout”. For this, you would want to paste the below-mentioned code on your website page, after the PushCrew SmartCode before closing </head> tag.
window._pcq = window._pcq || [];
|
PLEASE NOTE: Once the above task is performed, you do not need to manually create the “checkout” segment as it will be automatically created for the very first time the user visits this page.
You can now send notifications to this segment directly from the dashboard by going to Send New Notification button --> Send to --> Segment. In the image below, we have chosen the segment "House Stark".
You can also Segment users using Google Tag Manager.