Segment conditions: Javascript variable

If you have, or are able to expose, a variable in the website's global Javascript (window) context, you can use the value of that variable to segment your visitors within RightMessage.

Using the Javascript variable condition is a more advanced technique, that will need some technical / developer experience.

Unfortunately RightMessage does not have any generic copy/paste Javascript code to help set up custom variables on your website.

Below is an example of how to set up a Javascript variable condition.

For example, if a website is exposing the variable of 

window.fitnessgoals = "weight loss"

you can define your RightMessage segment like the below:

In the segment, select 'Javascript value' from the dropdown. 

Add the name of the Javascript value to the field provided.

Use the dropdown to select a keyword that will test the ‘truth’ of the Javascript Variable value and whether it is true or false.

  1. Equals: The custom parameter equals a specific value
  2. Doesn’t equal: The custom parameter does not equal a specific value
  3. Contains: The custom parameter contains a specific value
  4. Doesn’t contain: The custom parameter does not contain a specific value
  5. Starts With: The custom parameter value starts with something specific
  6. Ends With: The custom parameter value ends with something specific
  7. Wildcard Match: The custom parameter has a value that matches zero or more non-space characters, or one exact character.

Add the value of the custom parameter value to the field provided.

Using Google Tag Manager's dataLayer

This same method can be used to access data from your Google Tag Manager dataLayer.

Add the dataLayer before the RightMessage tracking snippet

The dataLayer needs to be loaded earlier in your site's template than the RightMessage snippet.

For example:

Extracting the data using Javascript

Because dataLayer is implemented as an array, you'll need to extract the data you need into a Javascript object for RightMessage to read. 

For example, if your dataLayer looks like:

window.dataLayer = [{ fitnessgoals: "weightloss", status: "client" }];

You'll want to put some Javascript like this after the dataLayer setup and before the RightMessage snippet:

window.rmDataLayer = window.dataLayer[0];

You can then access that data within RightMessage as rmDataLayer.industry and rmDataLayer.status.

Still need help? Contact Us Contact Us