Skip to main content
JavaScript
SmileUI.init({
  channel_key: "channel_0987654321",
  customer_identity_jwt:
    "eyJhbGciOiJIUzI1NiJ9.eyJjdXN0b21lcl9pZGVudGl0eSI6eyJkaXN0aW5jdF9pZCI6IjEwMCJ9LCJleHAiOjE1ODU1OTE1MzZ9.PGJhiM0NYRok5VGAlAOT6F-57gu7SCBaennQbt6YrqU",
});
This SmileUI.init() method is now deprecated and should no longer be used by new installations. This documentation is maintained as a reference only and a deadline for migrating to the new SmileUI.initialize() method will be announced shortly.
This method initializes Smile.js with information about the reward program to display and the currently logged in customer. This method must be called before you can interact with other methods provided by the SDK.
If you’re loading the Smile.js script asynchronously, you should wrap your initialization code within a loaded event to ensure it doesn’t encounter an error due to the script not yet being present on the page.

Parameters

options
object
required
A required object with the following keys:
  • channel_key - Your Smile.io Public Key. This is used for identifying your store and can be made public. Refer to the help docs for where to find it.
  • customer_identity_jwt - A signed JWT for the currently logged in customer on your site. See instructions below for generating a signed JWT. This should be null if no customer is currently logged in.

Generating a signed JWT

The signed JWT is what’s used to verify your store is the one requesting information from Smile.io on behalf of a customer. It should be generated using your platform’s server side language so your Smile.io Private Key remains secret. It must also have an expiration, for which we recommend 5 minutes.

Payload of the JWT

The payload of the JWT should be a hash containing the unique identifier in your system for the currently logged in customer. For example, if your Smile account is connected to Shopify, the unique identifier would be the Shopify Customer ID (e.g. 123456, not gid://shopify/Customer/123456). This value should never be the Smile Customer ID. We require the following format, where 100 is the customer’s unique identifier. Depending on the backend language and JWT library you’re using, you may need to include the JWT’s expiry directly in the payload.
JSON
{
  "customer_identity": {
    "distinct_id": "100"
  }
}

Code sample

Ruby
require "jwt"

# Unique identifier of the customer in your system (not the Smile Customer ID)
# For Shopify, use the numeric Shopify Customer ID (123456), not the fully
# qualified Shopify GraphQL ID (gid://shopify/Customer/123456)
customer_id = "100"

# Your Smile.io Private Key
private_key = "sk_1234567890"

payload = {
  customer_identity: {
    distinct_id: customer_id
  },
  exp: Time.now.to_i + 300 # Set expiry to 5 minutes
}
signed_jwt = JWT.encode(payload, private_key, "HS256")