First run for Snowplow event dictionary entries
With the event dictionary in place, we can start creating .yml
files for the current events. This will cover backend events first.
Used script
events.csv
description,category,action,product_section,product_group,distributions,tiers
description1,category1,action1,product_section1,product_group1,ce;ee,free
description2,category2,action2,product_section2,product_group2,ee,premium;ultimate
generator.js
const fs = require('fs');
const csv = require('csv-parser');
const SOURCE_FILE_PATH = './events.csv';
const FOLDER_PATH = './event_dictionary_generator_output';
const ARRAY_SEPARATOR = ';';
const baseTemplate = `description:
category:
action:
property_description:
value_description:
extra_properties:
identifiers:
product_section:
product_stage:
product_group:
product_category:
milestone:
introduced_by_url:
distributions:
tiers:
`;
createFolderIfNeeded();
iterateRows();
function createFolderIfNeeded() {
if (!fs.existsSync(FOLDER_PATH)) {
fs.mkdirSync(FOLDER_PATH);
}
}
function iterateRows() {
fs.createReadStream(SOURCE_FILE_PATH).pipe(csv()).on('data', createFileFromRow);
}
function createFileFromRow(row) {
let template = String(baseTemplate);
for (const [name, value] of Object.entries(row)) {
const label = `${name}:`;
const isArray = value.includes(ARRAY_SEPARATOR) || ['distributions', 'tiers'].includes(name);
if (isArray) {
const items = value.split(ARRAY_SEPARATOR).join('\n- ');
template = template.replace(label, `${label}\n- ${items}`);
} else {
template = template.replace(label, `${label} ${value}`);
}
}
console.log(template);
// Create file
}
Example output
description: description1
category: category1
action: action1
property_description:
value_description:
extra_properties:
identifiers:
product_section: product_section1
product_stage:
product_group: product_group1
product_category:
milestone:
introduced_by_url:
distributions:
- ce
- ee
tiers:
- free
description: description2
category: category2
action: action2
property_description:
value_description:
extra_properties:
identifiers:
product_section: product_section2
product_stage:
product_group: product_group2
product_category:
milestone:
introduced_by_url:
distributions:
- ee
tiers:
- premium
- ultimate
Edited by Axel García