Displaying Analytics

Learn how to begin displaying analytic events

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 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:

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"

["today", "this_day", "this_week", "this_month", "this_year", "yesterday", "last_day", "last_week", "last_month", "last_year"]

OR

An object with both start and end

as unix timestamps (see code above)

false

user_id

string

"no_tracked_user"

any

false

object_id

string

"no_object_id"

any

false

This method takes advantage of daily and total caching. It is built to be highly performant and snappy up to trillions of events queried.

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:

query-today.js
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} }

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:

query-week.js
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} }

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.