-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_script.mjs
32 lines (28 loc) · 1.07 KB
/
simple_script.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
This is a proof of concept of how to use Trackingplan with NodeJS
It's a simple script that sends events to Trackingplan without having a server
It also shows that Trackingplan can capture the end of the script
*/
import Trackingplan from 'trackingplan-node-sdk';
import analytics from './analytics.mjs';
Trackingplan.init("TP5551234567", {
debug: true,
batchInterval: 1,
//contentFilters: ["event6"]
});
async function sendEvents() {
/* Track page views */
analytics.track("event1", { prop1: "value1" });
analytics.track("event2", { prop1: "value1" });
analytics.track("event3", { prop1: "value1" });
analytics.track("event4", { prop1: "value1" });
await new Promise(resolve => setTimeout(resolve, 10000));
analytics.track("event5", { prop1: "value1" });
analytics.track("event6", { prop1: "value1" });
await new Promise(resolve => setTimeout(resolve, 1000));
Trackingplan.flush();
Trackingplan.stop();
analytics.track("event7", { prop1: "value1" });
analytics.track("event8", { prop1: "value1" });
}
sendEvents();