Using Audiences without GTM
If you can’t use Google Tag Manager, you can still make use of Audiences by manually storing descriptive “traits” in your users’ browser local storage. When a user searches on your website, the Cludo script will check for these stored traits and apply any associated Audiences to give the user a personalized search experience.
How to implement storing of traits
Storing traits without Google Tag Manager will require a bit of custom code, but it allows you to control Audiences from a different tag manager or entirely on your own with your own code.
When traits should be stored
Ultimately, it’s up to you when and for what reasons traits are stored for your users. Often, traits about a user are tracked after they do something important that you believe puts them into a particular group of users (or audience). If you’re using a tag manager application, this recognition of important actions is often called a trigger, and each trigger can lead to a response, which is sometimes called an action. For instance, when a user logs in (the trigger), you can run some custom code (the action) that adds isLoggedIn
to their list of traits. This way, you can provide them with a search experience that’s designed just for users who are logged in.
How traits should be stored
Traits should be stored under the local storage key “cludoTraits”. Although local storage only supports string type keys and values, the Cludo script will try to parse the value under the “cludoTraits” key and use it as an array of traits, so it’s important to first store traits in an array and then stringify the array before setting it in local storage:
let userTraits = ['isLoggedIn', 'visitedSupportPage'];
localStorage.setItem('cludoTraits', JSON.stringify(userTraits)];
In a similar fashion, you should parse the value if you need to read from or update the cludoTraits
array without fully overwriting it:
let userTraitsString = localStorage.getItem('cludoTraits') || '[]';
let userTraitsArr = JSON.parse(userTraitsString);
userTraitsArr.push('abandonedShoppingCart');
localStorage.setItem('cludoTraits', JSON.stringify(userTraitsArr)];
Once you are successfully storing traits in local storage, you’re ready to create Audiences in MyCludo that use those traits to deliver personalized search.