Skip to content

joe-ayoub-segment/LD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

Written By: Joe Ayoub
Last Updated: 26/09/21

Contents

  • Summary
  • Discussion
  • Instructions
  • Project Files
  • Settings
  • Launch Darkly Project and feature flag details
  • Segment project details

Summary:

This Node.js script demonstrates how user profile details could be migrated from one system to another with the aid of the launchDarkly Feature Flag service.

A feature flag is used to specify which users should be migrated and which should not. The selection criteria are based on user attributes in Launch Darkly.

For demonstration purposes the source user profiles are stored in a pipe delimited CSV file, however in a more real world scenario this data could be read in from a database. Also, for demonstration purposes a user profile is considered migrated after the user profile has been loaded into Segment using a Segment identify() API call. This API call could be replaced by an API call to any other service.

Discussion:

The 'service' I decided to use as the Destination service for migration is called 'Segment'. Segment is a Customer Data Platform which is capable of accepting user profile data and user analytics data, and can forward this data on to hundreds of different Marketing and Analytics tools.

I was able to create a mechanism to control which users get migrated from a flat file to Segment using a Feature Flag that looks at the user's attributes in LaunchDarkly. However this script has no way of knowing or checking if a user has already been migrated, so executing the script twice would result in the user being 'migrated' twice. If I had more time I'd look into fixing this issue.

Users can be migrated a single cohort at a time, with the cohort selection criteria being controled via a Feature Flag. Selecting a new cohort of users for migration is as simple as updating the eligible-for-migration Feature Flag selection criteria, then rerunning the script.

In the example below only users who have a CustomerClass = Trial will be migrated.

Instructions:

1. Install Node and NPM

See instructions

2. Clone the repo and install dependencies

Clone this repo, then open a terminal in the LaunchDarkly_Migration_App folder. Run the following commands in order:

npm init --yes
npm install fs
npm install launchdarkly-node-server-sdk
npm install csv-parse   
npm install analytics-node 

3. Run the migration script

Run the following terminal command:

node index.js

4. Output

The script will output logs indicating which users were migrated and which were not migrated

Project files:

There are 2 project files.

  • index.js
  • data/data_to_import.csv

1. index.js script file

This file contains a script that does the following when executed:

  1. Loads the user data from the data/data_to_import.csv file
  2. For each data row, check if the user is eligible for migration. This is done via a LaunchDarkly feature flag check
  3. If the user is eligible for migration, trigger a Segment identify() call to load the user's profile data into Segment.
  4. The following logs get written to standard output

2. data/data_to_import.csv data file

This file contains rows of user profile data, including the user's key (unique ID), user's name and other user attributes.

Settings:

All settings are stored in the index.js file.

The following are LaunchDarkly related settings, and relate to the LaunchDarkly project and Feature Flag being checked

The following are Segment related settings. The write_key setting indicates the location in Segment where the user profile data will be sent to.

Launch Darkly Project and feature flag details:

Here's a screenshot of the LaunchDarkly project:

Here's a screenshot of the user profiles loaded into LaunchDarkly

Here's a screenshot of the feature flag rules for the eligible-for-migration flag.

Segment project details:

When a user is migrated, an API call is sent to Segment which loads the user's profile into Segment.

Here's a screenshot of the API call being received by Segment.

Here's a screenshot of the user's profile in Segment's user profile engine

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published