User and session tests

Discover the different user and session tests available in CQL.

User and session tests are natural language conditions that you can use to check whether a user or session meets certain criteria. These tests include, for example, checking whether a user is anonymous or identified, or whether a session has just started.

The following table summarizes the available user and session tests for quick reference:

TestDescription
AnonymousChecks whether the user is anonymous.
IdentifiedChecks whether the user is identified.
ReturningChecks whether the user has accessed the application before.
Session startChecks whether the session has just started.

Anonymous

This test checks whether the user is anonymous, that is, whether they have not logged in or signed up yet. It is the opposite of the identified test.

Users are anonymous until they log in or sign up. After that, they remain identified until they log out.

Syntax

This test has the following syntax:

/*<user>*/ is anonymous
Try in Playground

To negate the test, you can write:

/*<user>*/ is not anonymous
Try in Playground

Consider using the identified test instead of negating this test for better readability.

Parameters

These are the supported parameters:

user

The user to check whether they are anonymous.

Examples

You can check whether a user is anonymous like this:

user is anonymous
Try in Playground

Identified

This test checks whether the user is identified, that is, whether they have logged in or signed up. It is the opposite of the anonymous test.

Users are identified after they log in or sign up and remain identified until they log out. Before logging in and after logging out, they are anonymous.

Syntax

This test has the following syntax:

/*<user>*/ is identified
Try in Playground

To negate the test, you can write:

/*<user>*/ is not identified
Try in Playground

Consider using the anonymous test instead of negating this test for better readability.

Parameters

These are the supported parameters:

user

The user to check whether they are identified.

Examples

You can check whether a user is identified like this:

user is identified
Try in Playground

Returning

This test checks whether the user is returning, that is, whether they have accessed the application before.

To determine if a user is a returning visitor, this test checks whether the user has more than one visit, which is equivalent to the following condition:

user's stats' sessions > 1
Try in Playground

Since visits are tracked automatically, this test requires no additional tracking beyond the regular integration.

Syntax

This test has the following syntax:

/*<user>*/ is returning
Try in Playground

To negate the test, you can write:

/*<user>*/ is not returning
Try in Playground

Parameters

These are the supported parameters:

user

The user to check whether they are returning.

Examples

Here is how you can check whether a user has visited the application before:

user is returning
Try in Playground

You can also check whether the user is a new visitor as follows:

user is not returning
Try in Playground

Session start

This test checks whether the session has just started, meaning that the user has just landed on the application.

To determine if a session has just started, this test checks whether the user is on their first page or screen view, which is equivalent to the following condition for page views:

session's stats' pageviews is <= 1
Try in Playground

Since page views are tracked automatically, this test requires no additional tracking beyond the regular integration.

Syntax

This test has the following syntax:

/*<session>*/ is starting
Try in Playground

To negate the test, you can write:

/*<session>*/ is not starting
Try in Playground

Parameters

These are the supported parameters:

session

The session to check whether it has just started.

Examples

Here is how you can check whether the user has just landed on the application:

session is starting
Try in Playground

To check whether the user is on subsequent pages or screens, you can use the following condition:

session is not starting
Try in Playground