# Event and Property History

Critical Moments builds a local database of all events, and a sampling of the history of each property. This database can be queried in conditions using functions described below. This unlocks powerful use cases combining the user's current state, with their usage and device history.

{% hint style="success" %}
**Privacy Built In**

This database is local to the user's device, not server based. All queries and evaluation happen locally on the user's device.
{% endhint %}

### Event History

Every event is stored in the event history database, and can be queried with the following functions:

* [eventCount](/conditional-targeting/syntax-and-operators.md#eventcount-eventname)
* [eventCountWithLimit](/conditional-targeting/syntax-and-operators.md#eventcountwithlimit-eventname-limitint)
* [latestEventTime](/conditional-targeting/syntax-and-operators.md#latesteventtime-eventname)

#### Example

Presenting an important call to action like "rate us" or "subscribe" has the best chance of success after the user gets value from the app, but you typically want to wait until they have completed the action a few times before asking. Here's an example for a reminders app, which asks them to rate, but only after marking a task as complete a few times, and waiting 60 days between asks:

`eventCount('completed_task') > 4 && (latestEventTime('asked_to_subscribe')  == nil || latestEventTime('asked_to_subscribe') < now() - duration('60d'))`&#x20;

### Property History

You can access property history via the [propertyEver](/conditional-targeting/syntax-and-operators.md#propertyever-propnamestring-value) function in conditions.

#### Example

Checking if the user isn't on low\_power\_mode can improve the chance a call to action like "rate us" or "subscribe" succeed. However some users leave it on permanently and you don't want to ignore them forever. Your conditional check can be improved by ensuring they have had it off at some time in the past:

`(!device_low_power_mode && propertyEver('device_low_power_mode', false))`&#x20;

#### Sampling Rate

Properties are sampled at different times:

* Custom properties are sampled when set
* Most properties are sampled on app startup
* Some properties that are power or time intensive are only sampled when accessed.&#x20;

See [here](https://github.com/CriticalMoments/CriticalMoments/blob/65c3bc7f8804cb959952b2e01fc21b635123435b/go/cmcore/data_model/properties.go#L85) for how each propety is sampled, and take into account the sampling style when using this function.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.criticalmoments.io/conditional-targeting/conditional-guides/event-and-property-history.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
