Earlybirds Javascript is a wrapper for the Earlybirds API. It includes functions that allows you to trigger an identify, get some recommandations, and track activities.
npm install earlybirds-js
This tutorial requires a basic understanding of the Earlybids API and we strongly recommend you to read the Earlybirds doc first.
First, we need to initialize the instance with a trackerKey using the init() method.
import Eb from 'earlybirds-js'
const eb = new Eb().getInstance()
eb.init('TRACKER_KEY')
Every time a user visits your page, you need to send an identify request to the API in order to retrieve his Earlybirds profile ID. See the Earlybirds doc (identify workflow).
const config = {
profile: {
datasources: [{
id: 'DATASOURCE_ID',
original_id: 'CUSTOMER_ID'
}]
}
}
eb.identify(config)
Earlybirds-js provides a getRecommendations method that takes a widgetId as parameter and return a promise that resolves to a list of recommendations
eb.getRecommendations('WIDGET_ID')
.then(recommendations => {
// ok
})
The trackActivity method allows you to track actions such as a view, a buy, ... Can be done anywhere after an identify
eb.trackActivity({
original_id: '[ORIGINAL_ID]',
quantity: '[QUANTITY]',
price: '[PRICE]',
verb: '[view | add-to-cart | buy | like | disklike | click-on-reco]'
})
If the Early Birds profileId is not known, you can replace it with the couple datasourceId / userId.
eb.getRecosForCluster('WIDGET_ID', 'CLUSTER_ID')
Retrieve results from several recommendation widgets.
eb.getRecommendationsMulti('WIDGET_IDS')
You can retrieve the list of user last activities, filtered by any verb.
Usage example:
-
Retrieve last products liked
-
Retrieve last items seen
-
Retrieve last buys
eb.getActivities('WIDGET_IDS', 'VERB')
Tests are made using Jest
npm run test