How to write advanced triggers for your surveys

Sometimes our built-in settings for when to trigger surveys may not fully meet your specific needs. This is especially true if you have data that is not included in your URL. 

Expressions

In the publish settings of the survey you can write a logical expression that must evaluate to true for the survey to be shown. 

Values to be evaluated can be either a Number, String or Boolean.  A number may be floating point or integer. Arrays or objects containing these types is also supported. The properties of an object can be accessed using the dot operator, and properties of an array by the in operator.

Values Description
43, -1.234 Number
"hello" String
true, false Boolean
" \" \\ " Escaping of double-quotes and blackslash in string
foo, a.b.c, 'foo-bar' External data, se next section

Note! Strings must be double-quoted! Single quotes are for external variables. 

 

Numeric arithmetic Description
x + y Add
x - y Subtract
x * y Multiply
x / y Divide
x ^ y Power
x mod y Modulo

Note! Modulo always returns a positive number: -1 mod 3 == 2.

 

Comparisons Description
x == y Equals
x != y Does not equal
x < y Less than
x <= y Less than or equal to
x > y Greater than
x >= y Greater than or equal to
x == y <= z Chained relation, equivalent to (x == y and y <= z)
x ~= y Regular expression match
x in (a, b, c) Equivalent to (x == a or x == b or x == c)
x not in (a, b, c) Equivalent to (x != a and x != b and x != c)

 

Boolean logic Description
x or y Boolean or
x and y Boolean and
not x Boolean not
if x then y else z If boolean x is true, return value y, else return z
( x ) Explicity operator precedence

 

Objects and arrays Description
(a, b, c) Array
a in b Array a is a subset of array b
x of y Property x of object y

 

Functions Description
abs(x) Absolute value
ceil(x) Round floating point up
empty(x) True if x is undefined, null, an empty array or an empty string
exists(x) True unless x is undefined or null
floor(x) Round floating point down
log(x) Natural logarithm
log2(x) Logarithm base two
log10(x) Logarithm base ten
max(a, b, c...) Max value (variable length of args)
min(a, b, c...) Min value (variable length of args)
round(x) Round floating point
sqrt(x) Square root

 

External data

The external data available at the time of evaluation. The best way to examine what data is available is using the javascript console on the website where the script is running. To examine the variable named data you need to run extellio.getData().

Name Description
window The global window object in the browser. This contains global variables, browser information etc. 
distribution Information about the survey that is being evaluated.
data All surveys and websites related to Extellio and the current script being used.

Examples

Triggered when survey is in the same language code as the browser language.

window.navigator.language == distribution.surveyLanguage

Triggered when my global variable loggedIn is true and the device type is DESKTOP

window.loggedIn and "DESKTOP" in distribution.deviceTypes