Client Data
<script>
SP.init("WEBSITE_ID", function () {
var client = SP.getClient();
SP.addTag('vip');
if (SP.hasSegment('returning_customers')) {
// ...
}
});
</script>Trustisto keeps the client in the browser. You can read it with the methods below, e.g. to personalize your page, and change the client’s tags and scoring. To save client details (e-mail, phone, consents), use Save Client.
Client
SP.getClient()- the saved client: the fields from Save Client, plusuid(the visitor ID),tags,segmentsandscoring. Returns{}when nothing is saved.
Tags, segments and scoring
Every client has tags, segments and a scoring. Trustisto sets them on its own based on events (as configured in the panel), and you can also read and change them from JavaScript.
When the client is known (identified by e-mail or phone), the changes are synced with Trustisto. Otherwise they are kept in the browser and synced once the client is identified.
Tags
SP.addTag(tag)- add one tagSP.addTags([tag1, tag2])- add a few tagsSP.removeTag(tag)- remove one tagSP.removeTags([tag1, tag2])- remove a few tagsSP.getTags()- all tags of the client, as an arraySP.hasTag(tag)-trueif the client has the tagSP.hasTags([tag1, tag2])-trueif the client has all the tagsSP.hasAnyTags([tag1, tag2])-trueif the client has at least one of the tags
Tags are normalized: characters other than letters, digits, _ and spaces are removed, and spaces are replaced with _. So "New customer!" becomes New_customer.
Segments
Segments are assigned by Trustisto, based on the segment rules defined in the panel. From JavaScript you can only read them:
SP.getSegments()- all segments of the client, as an arraySP.hasSegment(segment)-trueif the client is in the segmentSP.hasSegments([segment1, segment2])-trueif the client is in all the segmentsSP.hasAnySegments([segment1, segment2])-trueif the client is in at least one of the segments
Scoring
SP.getScoring()- the client’s current scoringSP.changeScoring(points)- add points to the scoring; pass a negative number to subtract
Watch form fields
<script>
SP.go('watchClient', '#checkout input[name="email"]', 'email');
SP.go('watchClient', '#checkout input[name="firstname"]', 'firstname');
</script>watchClient saves a client field whenever the value of a form field changes, so you don’t need to call Save Client yourself. It is handy on checkout and registration forms: the client is identified as soon as they type their e-mail, even if they never finish the order. It also works for the coupon code field.
SP.watchClient(selector, field, readOnStart, getValue)selector- CSS selector of the input(s) to watch. Inputs that are not on the page yet are looked for every 2.5 seconds, until they appear.field- the client field to save, e.g.email,phone,firstname,marketing.mail,couponCodereadOnStart-truesaves the current value as soon as the input is found (default:false)getValue- function that returns the value from the input (default:checkedfor checkboxes,valuefor other inputs)
Empty values are skipped. Each input is watched only once, even if you call watchClient for it again.
Stop watching
<script>
SP.go('clearWatchClient');
</script>clearWatchClient removes all watchers. It is also called automatically by recheckUrlTriggers.