How To Install & Use
This SDK uploaded on NPM as a package so you need to run this NPM command to install this package in your frontend app :
npm i smile-sdk
SDKHelper https://github.com/MawadaDev/santa-web/blob/15937df35b62f1658302eba6116c368ba0f6be49/src/SDKHelper/SDKHelper.ts#L4
This is a singleton class which contains instance of 2 classes : EventLogging and Recommendation.
The SDKHelper.initializeSDK method must be called inside the root index.js file for initialization.
SDKHelper.initializeSDK() takes 2 parmeters : https://github.com/MawadaDev/santa-web/blob/15937df35b62f1658302eba6116c368ba0f6be49/src/SDKHelper/SDKHelper.ts#L19
2. apiKey : String - for authentication purpose
Event Logging https://github.com/MawadaDev/santa-web/blob/15937df35b62f1658302eba6116c368ba0f6be49/src/producer/event-logging.ts#L6
This is a singleton class which contains a function for event logging : produceMessage(). You can use this function through SDKHelper class instance.
The SDKHelper.instance.eventLogger.produceMessage() method must be called every time an event is to be logged in Kafka.
SDKHelper.instance.eventLogger.produceMessage() takes 3 parameters : https://github.com/MawadaDev/santa-web/blob/15937df35b62f1658302eba6116c368ba0f6be49/src/producer/event-logging.ts#L123
2. sessionId : String? - The session ID of the user or null
3. data: JSONObject? - A JSON object which contains the specific details of that paticular event to be logged. For e.g. if the event is for "beginCheckout", then a Json object containing details of the user and products may be passed like :
{ "user": [ { "userId": "ab3e2387-3474-4fc3-ac0b-24d5b05730d6" } ], "product": [ { "productId": "5a2c8288-e52f-4894-a024-c49bef513d99" } ] }This JSON Object can contain anything or can be null in which case other details of the user will be logged without any specific event details.
The complete request payload :
{ "device": { "geoLocation": { "latitude": 23.076358, "longitude": 72.5096374 }, "operatingSystem": "Windows", "browser": "Chrome", "deviceCategory": "Desktop" }, "eventMeta": { "eventId": "aaa1491e-c92b-42f6-b99d-4e761e350252", "sessionId": "f775eb3b-c565-4693-9a3b-1ef27643989d", "eventType": "user-session-start", "user": [ { "userId": "a3b9a8c2-44a8-415d-a7cf-fca1adcdf217" } ], "product": [ { "productId": "6be855bb-f270-424b-886f-9caea3c55842" } ], "timestamp": 1708083881111 } }
The data: JSONObject? parameter of the logEvent method will be appended in the "eventMeta" json object.
Recommendation https://github.com/MawadaDev/santa-web/blob/15937df35b62f1658302eba6116c368ba0f6be49/src/recommendation/recommendation.ts#L3
This is a singleton class which contains 2 functions : getProductRecommendations() and getSimilarProducts(). You can use this function through SDKHelper class instance.
The SDKHelper.instance.productRecommendor.getProductRecommendations() method must be called when you want to show user specific recommendations.
SDKHelper.instance.productRecommendor.getProductRecommendations() takes 2 parmeters : https://github.com/MawadaDev/santa-web/blob/15937df35b62f1658302eba6116c368ba0f6be49/src/recommendation/recommendation.ts#L13
The SDKHelper.instance.productRecommendor.getSimilarProducts() method must be called when you want to show similar products of particular product.
SDKHelper.instance.productRecommendor.getSimilarProducts() takes 1 parameter : https://github.com/MawadaDev/santa-web/blob/15937df35b62f1658302eba6116c368ba0f6be49/src/recommendation/recommendation.ts#L40
2. callback : (SimilarProductsResponse?) -> Unit - This is a callback to receive the API response in form of Object of SimilarProductsResponse interface. https://github.com/MawadaDev/santa-web/blob/74c20121420bf439878bf89fa8f1213b513e0559/src/serializers/apiResponses.ts#L30