Created
May 9, 2018 18:19
-
-
Save nealrs/360ccd11fefaf5a51bd93170efbb2edc to your computer and use it in GitHub Desktop.
snowplow mini test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const snowplow = require('snowplow-tracker'); | |
const emitter = snowplow.emitter; | |
const tracker = snowplow.tracker; | |
// setup emitter | |
const e = emitter( | |
'com-spokenlayer.mini.snplow.net', // Collector endpoint | |
'https', // Optionally specify a method - http is the default | |
null, // Optionally specify a port | |
'POST', // Method - defaults to GET | |
1, // Only send events once n are buffered. Defaults to 1 for GET requests and 10 for POST requests. | |
function(error, body, response) { // Callback called for each request | |
if (error) { | |
console.log(`Request to Snowplow Collector failed: ${JSON.stringify(error, null, 2)}`); | |
} | |
else { | |
// console.log(`body: ${JSON.stringify(body, null, 2)}`); | |
console.log(response); | |
} | |
}, | |
{ maxSockets: 6 } // Node.js agentOptions object to tune performance | |
); | |
console.log(e); | |
// setup tracker | |
const t = tracker([e], 'SpokenLayer', 'voice apps', false); | |
console.log(t); | |
// params | |
const platform = 'smart-speaker'; | |
const publisher = 'Random Publisher'; | |
const uid = 'r@nd0mu$3r'; | |
const storyId = "just_some_story_id"; | |
// track structured data | |
t.setPlatform(platform); | |
t.setUserId(uid); | |
t.trackStructEvent('Foo', 'Bar', 'Baz', 'Derp', 'Merp'); | |
console.log(`Snowplow data: ${JSON.stringify(t, null, 2)}`); | |
// track unstructured data (audio start) | |
t.setPlatform(platform); | |
t.setUserId(uid); | |
t.trackUnstructEvent({ | |
"schema": "iglu:com-spokenlayer.mini.snplow.net/api/schemas/com.spokenlayer/story_start/jsonschema/1-0-0", | |
"data": { | |
"distributor": publisher, | |
"storyId": storyId | |
} | |
}); | |
console.log(`Snowplow data: ${JSON.stringify(t, null, 2)}`); | |
// track unstructured data (audio end) | |
t.setPlatform(platform); | |
t.setUserId(uid); | |
t.trackUnstructEvent({ | |
"schema": "iglu:com-spokenlayer.mini.snplow.net/api/schemas/com.spokenlayer/story_end/jsonschema/1-0-0", | |
"data": { | |
"distributor": publisher, | |
"storyId": storyId | |
} | |
}); | |
console.log(`Snowplow data: ${JSON.stringify(t, null, 2)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment