Web SDK API

Last updated:2023-02-21
Expand all
Web SDK API

SDK initialization

Supported version

Since: 2.0.0

API definition

  • init(initConfig)
  • Description:
  • Initialization API
  • Parameters
  • Config object

Example

window.JOperateInterface.init({ appKey: "9f7248bf870ddec7048e6c0b", // appkey assigned after creating an app on the Jiguang portal, required debugMode: true,// whether to enable debug mode; true prints more logs, false prints only w / e level channel: "default-channel",// channel name, default: default-channel })
           window.JOperateInterface.init({
 appKey: "9f7248bf870ddec7048e6c0b", // appkey assigned after creating an app on the Jiguang portal, required
 debugMode: true,// whether to enable debug mode; true prints more logs, false prints only w / e level
 channel: "default-channel",// channel name, default: default-channel
 })

        
This code block is shown in the floating window

Custom event tracking

Before calling this API, you must create the meta-event in the console. See Create meta-event.

Supported version

Since: 2.0.0

API definition

  • onEvent(event)
  • Description:
  • Custom event tracking
  • Parameters
  • event: the custom event model to report

Example

let event = {name:"name", attributes:{key:"value"}} window.JOperateInterface.onEvent(event)
           let event = {name:"name", attributes:{key:"value"}}
 window.JOperateInterface.onEvent(event)

        
This code block is shown in the floating window

Set user contact info

When a user's contact info changes, call this API to update the "Contact info" of the user's "Contact tag" under "Reach channel".

Supported version

Since: 2.0.0

API definition

  • setUserChannel(channel)
  • Description:
  • Set the user's "contact info" for the "contact tag" under the specified "channel ID".
  • The initial contact tag name is "Default Contact". To use a custom name, first add a Contact tag on the platform.
  • Supports setting values for multiple "contact tags" at the same time.
  • When setting "contact info" for "SMS", the value must be 11 digits (mobile-phone format).
  • Parameters
  • channel: user reach channel ID
  • Structure: {channel id: {contact tag: contact info}}
  • completion: callback

Example

let channel = { completion: (code, msg)=>{ }, channels: {} } let contact = {} contact["contact tag"] = "contact info" // e.g. work phone = 18800000000 channel.channels["580"] = contact // e.g. the channel ID created in the console is 580 window.JOperateInterface.setUserChannel(channel)
           let channel = {
 completion: (code, msg)=>{ },
 channels: {}
 }
 let contact = {}
 contact["contact tag"] = "contact info" // e.g. work phone = 18800000000
 channel.channels["580"] = contact // e.g. the channel ID created in the console is 580
 window.JOperateInterface.setUserChannel(channel)

        
This code block is shown in the floating window

Set user identifier

Supported version

Since: 2.0.0

API definition

  • identifyAccount(user);
  • Description:
  • Set a user identifier, e.g. membership card number.
  • Parameters
  • userID: user identifier ID
  • completion: callback

Example

let user = {completion: (code, msg)=>{}, userIDs:{"id":"value"}} window.JOperateInterface.identifyAccount(user)
           let user = {completion: (code, msg)=>{}, userIDs:{"id":"value"}}
 window.JOperateInterface.identifyAccount(user)

        
This code block is shown in the floating window

Get CUID

Supported version

Since: 2.0.0

API definition

  • + CUID()
  • Description:
  • Get the Operations Growth CUID

Example

window.JOperateInterface.CUID((code,cuid)=>{ })
           window.JOperateInterface.CUID((code,cuid)=>{

 })

        
This code block is shown in the floating window

Set UTM properties

Supported version

Since: 2.0.0

API definition

  • setUtmProperties(attrs:any)
  • Description:
  • UTM properties are preset properties. The following UTM properties can be set:
  • utm_source: campaign source
  • utm_medium: campaign medium
  • utm_term: campaign term
  • utm_content: campaign content
  • utm_campaign: campaign name

Example

window.JOperateInterface.setUtmProperties({"utm_source":"value1"})
                  window.JOperateInterface.setUtmProperties({"utm_source":"value1"})

        
This code block is shown in the floating window

Set static common properties

Supported version

Since: 2.0.0

API definition

  • setEventCommonAttr(property)
  • Description:
  • Register static common properties. All subsequently reported events include these properties. They are stored locally and persist long-term.
  • When an event property collides with a common property, the event property wins.
  • Key must be a String containing only digits, lowercase letters, and underscores, starting with a letter.
  • Value may be string/number/Array.
  • All elements of an Array must be string.

Example

window.JOperateInterface.setEventCommonAttr({"key1":"value1", "key2":"value2"})
                  window.JOperateInterface.setEventCommonAttr({"key1":"value1", "key2":"value2"})

        
This code block is shown in the floating window

Get static common properties

Supported version

Since: 2.0.0

API definition

  • currentEventCommonAttr()
  • Description:
  • Get the current static common properties for events.

Example

let attr = window.JOperateInterface.currentEventCommonAttr()
                  let attr = window.JOperateInterface.currentEventCommonAttr()

        
This code block is shown in the floating window

Clear all static common properties

Supported version

Since: 2.0.0

API definition

  • clearEventCommonAttr()
  • Description:
  • Remove all current static common properties.

Example

window.JOperateInterface.clearEventCommonAttr()
                  window.JOperateInterface.clearEventCommonAttr()

        
This code block is shown in the floating window

Set dynamic common properties

Supported version

Since: 2.0.0

API definition

  • setEventDynamicAttr(completion)
  • Description:
  • Register dynamic common properties. All subsequently reported events include the properties returned by this callback. The properties are valid only for the current registration.
  • When event property, static common property, and dynamic common property collide, override order is: event > dynamic common > static common.
  • Key must be a string containing only digits, lowercase letters, and underscores, starting with a letter.
  • Value may be string/number/Array.
  • All elements of an Array must be string.
  • dynamicProperties block returns the dynamic common properties for the event.

Example

window.JOperateInterface.setEventDynamicAttr(()=>{return {"key2":"value3", "key3":"value4"} })
           window.JOperateInterface.setEventDynamicAttr(()=>{return {"key2":"value3", "key3":"value4"}
 })

        
This code block is shown in the floating window

Set preset property: location

Supported version

Since: 2.0.0

API definition

  • setLocation(lat, lng)
  • Description:
  • Set the location field in the preset properties carried by reported events.

Example

window.JOperateInterface.setLocation(lat, lng)
                  window.JOperateInterface.setLocation(lat, lng)

        
This code block is shown in the floating window

Set user properties

Before calling, you must create the user property in the console. See Create user property.

Set user property (overwrite)

  • set(user, completion)
  • Description:
  • Set a user property in overwrite mode.
  • Only keeps the latest reported value, overwriting history, e.g. user membership level.
  • User property content is stored as an object; the key is the property name (must be string), and the value is the property content. Only string, number, and Array are supported.
  • For Array values, elements currently must be string.
  • If the property already exists, it will be overwritten; otherwise it will be created.
  • Example:
window.JOperateInterface.set({key:"value"}, (code, msg)=>{})
                  window.JOperateInterface.set({key:"value"}, (code, msg)=>{})

        
This code block is shown in the floating window

Set user property (first-write-only)

  • setOnce(user, completion)
  • Description:
  • Set a user property that takes effect only the first time.
  • Once a value is set, subsequent reports are ignored, e.g. first payment time.
  • Example:
window.JOperateInterface.setOnce({key:"value"}, (code, msg)=>{})
                  window.JOperateInterface.setOnce({key:"value"}, (code, msg)=>{})

        
This code block is shown in the floating window

Set user property (increment)

  • increment(user, completion)
  • Description:
  • Set a user property in increment mode.
  • Increase one or more numeric user properties by the reported amount, accumulating across reports, e.g. lifetime spend.
  • Only number-type user properties can be incremented; otherwise the call is ignored. If the property does not yet exist, the initial value is treated as 0.
  • Example:
window.JOperateInterface.increment({key:1}, (code, msg)=>{})
                  window.JOperateInterface.increment({key:1}, (code, msg)=>{})

        
This code block is shown in the floating window

Set user property (append)

  • append(key, content completion)
  • Description:
  • Set a user property in append mode.
  • Continuously appends elements to the collection, deduplicated. If ABC already exists and you append CD, the final value is ABCD. Example: news articles a user liked.
  • Adds values to an Array-type property. Elements must be string; otherwise ignored. If the property does not yet exist, it is initialized to an empty Array.
  • Example:
window.JOperateInterface.append("key",["value1", "value2"], (code, msg)=>{})
                  window.JOperateInterface.append("key",["value1", "value2"], (code, msg)=>{})

        
This code block is shown in the floating window

Remove user property

Supported version

Since: 2.0.0

API definition

  • unset(key, completion)
  • Description:
  • Remove all content of a user property.
  • If the property does not exist, the call is ignored.

Example

window.JOperateInterface.unset("key", (code, msg)=>{})
                  window.JOperateInterface.unset("key", (code, msg)=>{})

        
This code block is shown in the floating window

Event timing

Start event timing

  • timeKeepingEventStart(eventName)
  • Description:
  • To measure how long an event lasts, call timeKeepingEventStart("eventName") at the start to record the begin time; this call does not actually send the event.
  • Later, at the end, call timeKeepingEventEnd("eventID").
  • Example:
let eventID = window.JOperateInterface.timeKeepingEventStart("eventName")
                  let eventID = window.JOperateInterface.timeKeepingEventStart("eventName")

        
This code block is shown in the floating window

End event timing

  • timeKeepingEventEnd(eventId, properties)
  • Description:
  • End event timing. If called multiple times, only the first call takes effect.
  • Example:
window.JOperateInterface.timeKeepingEventEnd(eventID, {key:"value"})
                  window.JOperateInterface.timeKeepingEventEnd(eventID, {key:"value"})

        
This code block is shown in the floating window

Pause event timing

  • timeKeepingEventPause(eventID)
  • Description:
  • If called multiple times, only the first call takes effect.
  • Example:
window.JOperateInterface.timeKeepingEventPause(eventID)
                  window.JOperateInterface.timeKeepingEventPause(eventID)

        
This code block is shown in the floating window

Resume event timing

  • timeKeepingEventResume(eventID)
  • Description:
  • If called multiple times, only the first call takes effect.
  • Example:
window.JOperateInterface.timeKeepingEventResume(eventID)
                  window.JOperateInterface.timeKeepingEventResume(eventID)

        
This code block is shown in the floating window

Remove event timing

  • removeTimeKeepingEvent(eventID)
  • Description:
  • If called multiple times, only the first call takes effect.
  • Example:
window.JOperateInterface.removeTimeKeepingEvent(eventID)
                  window.JOperateInterface.removeTimeKeepingEvent(eventID)

        
This code block is shown in the floating window

Clear all timing events

  • clearTimeKeepingEvent()
  • Description:
  • Clear all timing events.
  • Example:
window.JOperateInterface.clearTimeKeepingEvent()
                  window.JOperateInterface.clearTimeKeepingEvent()

        
This code block is shown in the floating window

Enter data validation mode

  • openDebugMode()
  • Description:
  • Enter data validation mode.
  • Example:
window.JOperateInterface.openDebugMode()
                  window.JOperateInterface.openDebugMode()

        
This code block is shown in the floating window

Demo APIs

Get user data

  • userData(completion)
  • Description:
  • The callback returns user data, e.g. user events registered in the console, current user's channel info, user identifier, etc.
  • Example:
window.JOperateInterface.userData((code, data)=>{})
           window.JOperateInterface.userData((code, data)=>{})

        
This code block is shown in the floating window

UserID model

User identifier model. Properties:

Name Type Description
userIDs object Identifier IDs object
completion (code, msg)=>{} Result callback; errcode 0 = success

Event model

Custom event object. All string properties must not exceed 256 bytes (including keys in extra). Properties:

Name Type Description
eventName string Event ID, required, non-empty
property object Custom properties (≤500). Keys are string with only digits, letters, underscores; values are string/number

UserChannel model

User channel model. Properties:
If unset or set to nil, the channel is left unchanged; setting to an empty string "" clears that channel.

Name Type Description
channels object Channel dictionary
completion (code, msg)=>{} Result callback; errcode 0 = success
Was this document helpful?

Copyright 2011-2026, jiguang.cn, All Rights Reserved. 粤ICP备12056275号-13 Shenzhen Hexun Huagu Information Technology Co., Ltd.

Open in Docs Center