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:
Test | Description |
---|---|
Anonymous | Checks whether the user is anonymous. |
Identified | Checks whether the user is identified. |
Returning | Checks whether the user has accessed the application before. |
Session start | Checks 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.
This test uses the signed-in, signed-up, and signed-out events to determine whether the user is anonymous. Without it, the user is treated as anonymous.
Syntax
This test has the following syntax:
/*<user>*/ is anonymous
To negate the test, you can write:
/*<user>*/ is not anonymous
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
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.
This test uses the signed-in, signed-up, and signed-out events to determine whether the user is identified. Without it, the user is treated as anonymous.
Syntax
This test has the following syntax:
/*<user>*/ is identified
To negate the test, you can write:
/*<user>*/ is not identified
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
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
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
To negate the test, you can write:
/*<user>*/ is not returning
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
You can also check whether the user is a new visitor as follows:
user is not returning
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
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
To negate the test, you can write:
/*<session>*/ is not starting
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
To check whether the user is on subsequent pages or screens, you can use the following condition:
session is not starting