forked from PostHog/posthog-hello-world-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (29 loc) · 959 Bytes
/
index.js
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
async function setupPlugin({ config, global }) {
const base64 = Buffer.from(config.clearbitKey + ":" + '').toString('base64');
const authHeader = "Basic " + base64;
global.clearbitAuth = authHeader;
global.setupDone = true
}
async function processEvent(event, { global, cache }) {
if (event.ip) {
let response = await cache.get(event.ip);
let data = response ? JSON.parse(response) : null;
if (!data) {
response = await fetch('https://reveal.clearbit.com/v1/companies/find?ip=' + event.ip, {
headers: {
Authorization: global.clearbitAuth
}
})
data = await response.json();
cache.set(event.ip, JSON.stringify(data));
}
event.properties['companyName'] = data?.company?.name;
event.properties['companyDomain'] = data?.company?.domain;
return event
}
return event
}
module.exports = {
setupPlugin,
processEvent,
}