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:
1
await Plaudy.count({
2
"events": [
3
"purchase",
4
"click",
5
"visit"
6
],
7
"timeframe": {
8
"start": 1597079145327,
9
"end": +new Date()
10
},
11
"user_id": "USER_ID" // if you didn't pass this in when using .identify()
12
"object_id": "OBJECT_ID" // if you didn't pass this in when using .identify()
13
});
Copied!

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
1
import Plaudy from 'plaudy';
2
3
Plaudy.init(`YOUR_API_KEY`);
4
Plaudy.identify(`USER_ID`, `OBJECT_ID`);
5
6
const counts = await Plaudy.count({
7
"events": [
8
"page view"
9
],
10
"timeframe": "today",
11
});
12
13
console.log('COUNTS:', counts);
14
// COUNTS: { `OBJECT_ID`: {"page view": 1492} }
Copied!

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
1
import Plaudy from 'plaudy';
2
3
Plaudy.init(`YOUR_API_KEY`);
4
Plaudy.identify(`USER_ID`, `OBJECT_ID`);
5
6
const counts = await Plaudy.count({
7
"events": [
8
"click",
9
"page view"
10
],
11
"timeframe": "this_week",
12
});
13
14
console.log('COUNTS:', counts);
15
// COUNTS: { `OBJECT_ID`: {"click": 42, "page view": 525600} }
Copied!
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 [email protected].
Last modified 1yr ago