test

Evaluate a CQL condition in real-time.

This method evaluates a  CQL query as a boolean predicate.

It is essentially a shorthand for calling the evaluate method and checking whether the result is strictly equal to true.

Signature

This method has the following signature:

croct.test(query: string, options?: EvaluationOptions): Promise<boolean>

The return is a Promise that resolves to true if the query evaluates to true, false otherwise.

Example

Here is a basic example of how to use this method:

croct.test("user's interests includes 'sports'").then(console.log);

Parameters

The following list describes the supported parameters:

query
string

The  CQL query to evaluate, with a maximum length of 500 characters.

options(optional)
object

The evaluation options.

timeout(optional)
number

The maximum fetch time in milliseconds.

Once reached, the SDK will abort the request and reject the promise with a timeout error.

attributes(optional)
object

The map of attributes to inject in the evaluation context.

The attributes can be referenced in audience conditions using the context variable. For example, suppose you pass the following attributes:

{cities: ["New York", "San Francisco"]}

You can then reference them in queries like:

context's cities include location's city

For more information, see Context variables.

The following restrictions apply to the attributes:

  • Up to 30 entries and 5 levels deep
  • Keys can be either numbers or non-empty strings with a maximum length of 50 characters
  • Values can be null, numbers, booleans, strings (up to 50 characters), or nested maps
  • Nested maps follow the same constraints for keys and values