How to use

In order to get and set data, the commands need to be implemented properly, following the instructions detailed in this section.

How to send commands?

You can send commands to Rosetta.ai by the following method:

rosettaData.command(name, params, cb)

name - 'config' | 'query' | 'event' | 'purchase'

params - based on the command name

cb - callback function, some commands support this

config

The config command is used to set up your app id and user id. This is not really needed for Plugin only users.

Sending config command by the following method:

rosettaData.command('config', params)

● If you are using SDK file

If you want to use the SDK file, then first thing to do is to call the config command for setting up the app ID. You need to do this before any other command in your code!

The app ID will be provided at the very beginning of Rosetta.ai service. You can set the value by config command.

● If you are using plugin file

You are using the plugin file, then you don't really need to set the app id because this is automatically done for you by in that file. However, if you still want to use custom data (like for example your Line app id), then you can use this command for setting this type of information.

Example

rosettaData.command('config', {
  appId: 'app_ID',
  shopperId: 'shopper_ID',
  contact: {
    line_id: 'line_user_1'
  },
})

Parameters

The following are the accepted parameters. You can send them in a JSON as seen in the example above

query

Sending query command by the following method:

rosettaData.command('query', params, cb)

Via Sending query command with the parameters to fetch the API and get the data from the callback function.

Example

rosetta('query', {
  engines: ['engine_ID_1', 'engine_ID_2'],
  items: ['product_1'],
  filters: {
    categoryTree: ['New Arrival', 'Summer'],
  }
}, function (response) {
  console.log(response)
  /**
   * Render your own UI here
   */
})

Parameters

The following are the accepted parameters. You can send them in a JSON as seen in the example above

Example of response

The response is an array of object

[{
  "id": "query_ID",
  "data": [{
    "item": 12345678,
    "property": {
        "local_id": "product_ID",
        "name": "product_name",
        "description": "product_description",
        "link": "product_link",
        "image_link": "product_image_link",
        "price": "1000.0",
        "currency": "TWD",
        "availability": "in stock",
        "vendor_name": "Rosetta Shop",
        "category_tree": [
            "On Sale",
            "50% Off"
        ],
        "sale_price": "500.0",
        "item_group_id": "product_ID",
        "type": "item"
    },
    "score": 1.0
  }],
  "created_at": 1592976508
}]

event

The event command is used to record your users' actions.

By doing so, you increase the reliability and accuracy of predictions over the time.

Event Types

Remember that you only need to send attribution data is in click events. You don't need to send attribution data in other types of events. Rosetta will automatically record the attribution for the rest of the actions (select, unselect, etc.).

Examples

render

rosettaData.command('event', {
  type: "render",
  provider: "rosetta",
  context: "rosetta-carousel",
})

view

rosettaData.command('event', {
  type: "view",
  provider: "rosetta",
  context: "rosetta-carousel",
  source: "roestta_query_ID",
})

click

Please send the event command with attribution data(provider, context, source).

rosettaData.command('event', {
  type: "click",
  provider: "rosetta",
  context: "rosetta-carousel",
  source: "roestta_query_ID",
  target: "product_1",
})

select

Do not need to send the event command with attribution data.

rosettaData.command('event', {
  type: "select",
  target: "product_1",
})

unselect

Do not need to send the event command with attribution data.

rosettaData.command('event', {
  type: "unselect",
  target: "product_1",
})

You must have these events defined throughout your site. By not doing so, the accuracy of predictions will suffer greatly.

Parameters

The following are the accepted parameters. You can send them in a JSON as seen in the example above

purchase

The purchase command is used to record the data of the orders that your customers make.

Sending purchase command by the following method:

rosettaData.command('purchase', params)

Example

rosettaData.command('purchase', {
    orderNumber: "20220726042044309",
    currency: "TWD",
    total: 300,
    products: [
        {
            quantity: 1,
            target: "product_ID_1",
            total: 100
        },
        {
            quantity: 4,
            target: "product_ID_2",
            total: 200
        }
    ]
})

Parameters

The following are the accepted parameters. You can send them in a JSON as seen in the example above

If you have any installation questions, feel free to contact us: Rosetta.aiMediumFacebook

Last updated