# Intro to Conditions

Conditions are boolean string expressions that can be evaluated with the current state of the users device. A few examples show the range of possiblities:

* UI State: `interface_orientation == 'landscape' || dark_mode || screen_brightness < 0.1`
* Device state: `user_interface_idiom == 'tablet' || device_orientation == 'face_up' || device_model_version == '13.3' || device_battery_level > 0.25`&#x20;
* Locale: `locale_language_code IN ['en', 'es'] && locale_currency_code == 'USD'`&#x20;
* App info: `versionGreaterThan(app_version, '1.4.2') && app_install_date < date('2021-06-06')`&#x20;
* Networking state: `network_connection_type != 'cellular' && has_active_network && !low_data_mode && !expensive_network`
* Location: `location_approx_city == 'Toronto' || location_region == 'TX'`
* And much more: `!on_call && (has_bt_headset || has_wired_headset) && !has_watch && contacts_permission && canOpenUrl('spotify:')`&#x20;

### Properties

Conditions can evaluate over 100 properties:

* [Built in properties](https://docs.criticalmoments.io/conditional-targeting/built-in-properties): our SDK includes over 100 realtime device conditions from device orientation to "is it raining where the user is". See a [complete list](https://docs.criticalmoments.io/conditional-targeting/built-in-properties) of built in properties.
* [Custom properties](https://docs.criticalmoments.io/conditional-targeting/custom-properties): add your own data like "is this a power user" or "date of original account creation". Anything that makes sense for your app or use case.
* [Property history database](https://docs.criticalmoments.io/conditional-targeting/conditional-guides/event-and-property-history): check the history of any property to see if it has ever held a specific value, when it occurred, or how often it's happened. Allowed for powerful personalized decision making. The database is completely private: data is stored on the user's device, evaluated locally, and never sent off device.

### Functions

Conditions allow for inline functions like [date parsing](https://docs.criticalmoments.io/conditional-targeting/conditional-guides/working-with-dates), [random number generation](https://docs.criticalmoments.io/syntax-and-operators#random-number-generation), [parsing version numbers](https://docs.criticalmoments.io/syntax-and-operators#version-number-operators), URL support (`canOpenURL`), and more.

[Event history](https://docs.criticalmoments.io/conditional-targeting/conditional-guides/event-and-property-history) functions can query the built in database of event history, counting how many times a user has performed an action, or when the last time it was performed.

### Powerful Syntax

Conditional expressions support a wide range of operators including order of operation (`()`), arithmetic (`+, -, %, /, *, ^, **`), strings (`startsWith, endsWith, contains`), regex, ranges, and much more.&#x20;

This powerful set of features can be used to

* Multi-variable thresholding: `device_battery_level > 0.2 && eventCount('app_start') > 5`
* Multi-variable scoring: `(eventCount('completed_task_1') * 2) + (eventCount('completed_task_2') * 3) > 15`&#x20;
* Combine different use cases: for example, a feature flag with progress rollout, while only targeting new iPhones for the initial cohort (exclude iPads and old OSs)

See the [full syntax docs](https://docs.criticalmoments.io/conditional-targeting/syntax-and-operators) for details.

### Realtime Evaluation

Conditions are evaluated realtime, and will update their result as device state changes.

### Integration

Conditions are connected to the rest of the system through the [config file](https://docs.criticalmoments.io/config-file-structure). The following parts of the config file can include an condition strings:

* [Actions](https://docs.criticalmoments.io/actions-in-app-messaging/actions-overview) and [Triggers](https://docs.criticalmoments.io/actions-in-app-messaging/triggers) may optionally contain a condition, and only perform the action if the condition is true
* [Conditional actions](https://docs.criticalmoments.io/actions-in-app-messaging/conditional-actions): are actions which check a condition, and fire one action by name if true, and another if false
* [Feature Flags](https://docs.criticalmoments.io/feature-flags) can return their value based on a conditional string, and be updated over time with [remote updates](https://docs.criticalmoments.io/config-file-structure).
* [Named conditions](https://docs.criticalmoments.io/feature-flags/named-conditions-config) can evaluate conditions in code. Use them instead of manually writing complex conditional logic in code.
