smile-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.2.4 • Public • Published

This is an Web SDK Module which houses the code for Event Streaming & Recommendation features.

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

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.

1. baseUrl : String - the base url for example "http://15.206.124.223". ✔️ The API endpoint is configured to begin with "/" so no need to add "/" at the end of the base url like "http://15.206.124.223/" ✖️
2. apiKey : String - for authentication purpose

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.

1. eventType : String - The type of event you want to log.
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.

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

1. userId : String - The unique userId of the logged in user. 2. size : Int - How many products you want to show in products recommendation page. 3. callback : (ProductRecommendationResponse?) -> Unit - This is a callback to receive the API response in form of Object of ProductRecommendationResponse interface. https://github.com/MawadaDev/santa-web/blob/f36934558f509b5ef26fbf9f52dda797abf4f4f6/src/serializers/apiResponses.ts#L18

The SDKHelper.instance.productRecommendor.getSimilarProducts() method must be called when you want to show similar products of particular product.

1. productId : String - The unique product id of product for which you want to get similar products.
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

Readme

Keywords

none

Package Sidebar

Install

npm i smile-sdk

Weekly Downloads

6

Version

2.2.4

License

ISC

Unpacked Size

39.3 kB

Total Files

15

Last publish

Collaborators

  • sumitjamnani