-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piano Analytics Tag.tpl
38 lines (30 loc) · 1.01 KB
/
Piano Analytics Tag.tpl
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
33
34
35
36
37
38
//necessary APIs
const getAllEventData = require('getAllEventData');
const sendHttpRequest = require('sendHttpRequest');
const JSON = require('JSON');
let queryParams;
//get all event data
const event = getAllEventData();
//
if (data.siteId) {
queryParams = "s="+data.siteId+"&idclient="+event.client_id;
} else {
queryParams = "s="+event.site_id+"&idclient="+event.client_id;
}
//construct the request URL consisting of collection domain, path, and query string
let url = 'https://'+ data.collectDomain + data.requestPath + '?' + queryParams;
//set request headers
let headers = {};
headers["user-agent"] = event.user_agent;
headers["x-forwarded-for"] = event.ip_override;
//header parameters allowing you to have the response from the server in preview mode
headers["Content-Type"] = "application/json";
//set request body
const postBody = '{"events":['+ JSON.stringify(event.event) +']}';
//make POST request
sendHttpRequest(url, {
headers: headers,
method: 'POST',
timeout: 500,
}, postBody);
data.gtmOnSuccess();