> For the complete documentation index, see [llms.txt](https://docs.plaudy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.plaudy.com/displaying-analytics.md).

# Displaying Analytics

## Count

Count is powerful but surprisingly simple. This is the most performant call you can make when querying analytics. Any required fields or custom data fields are queryable, with the main fields to keep in mind being `object_id` [when applicable](/master.md#identify-optional) and `events`.

When performing any query type, we always use `events` as an array of event names or objects (if more complex querying) like so:

```javascript
await Plaudy.count({
    "events": [
        "purchase",
        "click",
        "visit"
    ],
    "timeframe": {
        "start": 1597079145327,
        "end": +new Date()
    },
    "user_id": "USER_ID" // if you didn't pass this in when using .identify()
    "object_id": "OBJECT_ID" // if you didn't pass this in when using .identify()
});
```

### Options

| Name       | Type           | Default             | Values                                                                                                                                                                                                                                                                          | Required |
| ---------- | -------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| events     | array          | \[ ]                | any                                                                                                                                                                                                                                                                             | true     |
| timeframe  | string, object | "all\_time"         | <p>\["today", "this\_day", "this\_week", "this\_month", "this\_year", "yesterday", "last\_day", "last\_week", "last\_month", "last\_year"]<br></p><p>OR</p><p></p><p>An object with both <code>start</code> and <code>end</code> </p><p>as unix timestamps (see code above)</p> | false    |
| user\_id   | string         | "no\_tracked\_user" | any                                                                                                                                                                                                                                                                             | false    |
| object\_id | string         | "no\_object\_id"    | any                                                                                                                                                                                                                                                                             | false    |

{% hint style="success" %}
This method takes advantage of daily and total caching. It is built to be highly performant and snappy up to trillions of events queried.
{% endhint %}

## Examples

### 1. Count page views today

Here's an example in a single file we'll call `query-today.js`. We'll be getting a count of today's page views:

{% code title="query-today.js" %}

```javascript
import Plaudy from 'plaudy';

Plaudy.init(`YOUR_API_KEY`);
Plaudy.identify(`USER_ID`, `OBJECT_ID`);

const counts = await Plaudy.count({
    "events": [
        "page view"
    ],
    "timeframe": "today",
});

console.log('COUNTS:', counts);
// COUNTS: { `OBJECT_ID`: {"page view": 1492} }
```

{% endcode %}

### 2. Count clicks and page views this week

Here's an example in a single file we'll call `query-week.js`. We'll be getting a count of today's page views:

{% code title="query-week.js" %}

```javascript
import Plaudy from 'plaudy';

Plaudy.init(`YOUR_API_KEY`);
Plaudy.identify(`USER_ID`, `OBJECT_ID`);

const counts = await Plaudy.count({
    "events": [
        "click",
        "page view"
    ],
    "timeframe": "this_week",
});

console.log('COUNTS:', counts);
// COUNTS: { `OBJECT_ID`: {"click": 42, "page view": 525600} }
```

{% endcode %}

Aaaand just like that, you have working customer-facing analytics! 💥Applying this gives you unlimited potential for customer engagement through metrics.

If you have any questions, feel free to reach out any time if you need help at <hi@plaudy.com>.
