Authors -- Maxime Wauthy & Glenn Vanderlinden @Human37
The Fakestream package is developed in order to generate synthetic data using Faker and send it to Segment, which in turn can dispatch it to final destinations. We have chosen to send it to Segment as Segment can act as a event pipeline from which data can then be distributed towards a number of tools for testing, training and demo applications. One SDK to rule them all if you will.
Out of the box the script will generate event for the following customer journey. To modify see the section on event creation.
- Unlocking the Power of Synthetic Data – A short introduction
- Synthetic data - An introduction to Faker.js
- Synthetic data - A practical application
On MacOS - Go to your folder location in which the script is stored using terminal. Then execute the following:
To install the Faker.js library:
npm install @faker-js/faker --save-dev
To install the Segment Node library:
npm install @segment/analytics-node
Insert your Segment write key.
const analytics = new Analytics({
writeKey: "{{INSERT KEY HERE}}",
});
Define the number of user you would like to be generated.
const numUsers = 10;
Create events in the templated structure.
{
name: "CTA Selected",
properties: {
cta_type: ["Sign-up Now", "Sign-up For Free"],
},
probability: 1.0,
}
Where
- name -- corresponds to the event name
- Properties -- properties contains the relevant properties linked to an event. The value can be an array of possible values you wish to eventually send with the event payload. The value which will eventually be chosen at random.
- Probability -- Indicates the chance that this event will be executes where 1.0 represents 100% chance.
Add traits where needed
function generateUser() {
const userId = faker.string.uuid();
const name = faker.person.fullName();
const userTraits = {
company: faker.company.name(),
name: name,
email: `${name.split(" ")[1].toLowerCase()}${Math.round(
Math.random() * 100
)}@fakeHuman.37`,
};
return { userId, userTraits };
}
In your IDE hit run.
In terminal - navigate to the root folder and run:
node FakeStream.js