MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / trackEvent

Function trackEvent

appengine/analytics/app.js:28–52  ·  view source on GitHub ↗
(category, action, label, value)

Source from the content-addressed store, hash-verified

26const {GA_TRACKING_ID} = process.env;
27
28const trackEvent = (category, action, label, value) => {
29 const data = {
30 // API Version.
31 v: '1',
32 // Tracking ID / Property ID.
33 tid: GA_TRACKING_ID,
34 // Anonymous Client Identifier. Ideally, this should be a UUID that
35 // is associated with particular user, device, or browser instance.
36 cid: '555',
37 // Event hit type.
38 t: 'event',
39 // Event category.
40 ec: category,
41 // Event action.
42 ea: action,
43 // Event label.
44 el: label,
45 // Event value.
46 ev: value,
47 };
48
49 return fetch('http://www.google-analytics.com/debug/collect', {
50 params: data,
51 });
52};
53
54app.get('/', async (req, res, next) => {
55 // Event value must be numeric.

Callers 1

app.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected