Skip to main content

Getting Started

This document describes the initial setup of the JavaScript SDK (hereinafter referred to as "SDK").

General Cases

If your web service consists of multiple pages and loads new static resources each time a page is requested, refer to the guide below.

info

Web services that operate in the manner described above are called MPA (Multi Page Application).

Step 1: Insert the SDK

Insert the script below inside the <body> tag of the HTML file.

<script>
!function(e,t,n,c,s,a,i){e[s]=e[s]||["init","event"].reduce(((t,n)=>({...t,[n]:function(){e[s]?.q.push([n,arguments])}})),{q:[]}),a=t.createElement(n),i=t.getElementsByTagName(n)[0],a.async=1,a.src="https://cdn.omnicommerce.ai/sdk/broswer/latest/main.js?v="+(new Date).getDate(),i.parentNode.insertBefore(a,i)}(window,document,"script",0,"OpmIO");
</script>

Step 2: Run the SDK

To use the SDK, insert the issued api key and run the SDK.

OpmIO.init("YOUR_PLUGIN_KEY"); // fill your plugin key

For a detailed description of the methods provided by the SDK, refer to the A SDK Event.

Single Page Application

If your web service is a Single Page Application (SPA) or you are using the SDK as a Javascript class, please refer to the example code below.

caution

The SDK should be used on the client-side only. The SDK cannot be pre-executed on the server-side.

Step 1: Add Service

Service for JavaScript

class OpmIOService {
constructor() {
this.loadScript();
}

loadScript() {
!function(e,t,n,c,s,a,i){e[s]=e[s]||["init","event"].reduce(((t,n)=>({...t,[n]:function(){e[s]?.q.push([n,arguments])}})),{q:[]}),a=t.createElement(n),i=t.getElementsByTagName(n)[0],a.async=1,a.src="https://cdn.omnicommerce.ai/sdk/broswer/latest/main.js?v="+(new Date).getDate(),i.parentNode.insertBefore(a,i)}(window,document,"script",0,"OpmIO");
}

init(name) {
window.OpmIO.init(name);
}

event(name, option) {
window.OpmIO.event(name, option);
}
}

export default new OpmIOService();

Step 2: Installation

You can install the SDK through the Service added in Step 1.

OpmIOService.loadScript();

Step 3: Run the SDK

To use the SDK, insert the issued API key and run the SDK.

OpmIOService.init("YOUR_PLUGIN_KEY"); // fill your plugin key

For a detailed description of the methods provided by the SDK, refer to the SDK Event.