MiniProgram SDK API
Last updated:2023-02-21
Expand all
MiniProgram SDK API
SDK initialization
Supported version
Since: 2.0.0
API definition
- init(context)
- Description:
- Initialization API
- Parameters
- App object
Example
joperate.init(this)
joperate.init(this)
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"}}
joperate.onEvent(event)
let event = {name:"name", attributes:{key:"value"}}
joperate.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[param["contact tag"]] = contact_info // e.g. work phone = 18*********
channel.channels["580"] = contact // e.g. the channel ID created in console is 580
joperate.setUserChannel(channel)
let channel = {completion: (code, msg)=>{ },
channels: {}}
let contact = {}
contact[param["contact tag"]] = contact_info // e.g. work phone = 18*********
channel.channels["580"] = contact // e.g. the channel ID created in console is 580
joperate.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"}}
joperate.identifyAccount(user)
let user = {completion: (code, msg)=>{}, userIDs:{"id":"value"}}
joperate.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
let cuid = joperate.CUID()
let cuid = joperate.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
joperate.setUtmProperties({"utm_source":"value1"})
joperate.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
joperate.setEventCommonAttr({"key1":"value1", "key2":"value2"})
joperate.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 = joperate.currentEventCommonAttr()
let attr = joperate.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
joperate.clearEventCommonAttr()
joperate.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.
dynamicPropertiesblock returns the dynamic common properties for the event.
Example
joperate.setEventDynamicAttr(()=>{return {"key2":"value3", "key3":"value4"}
})
joperate.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
joperate.setLocation(lat, lng)
joperate.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:
joperate.set({key:"value"}, (code, msg)=>{})
joperate.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:
joperate.setOnce({key:"value"}, (code, msg)=>{})
joperate.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:
joperate.increment({key:1}, (code, msg)=>{})
joperate.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:
joperate.append("key",["value1", "value2"], (code, msg)=>{})
joperate.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
joperate.unset("key", (code, msg)=>{})
joperate.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 = joperate.timeKeepingEventStart("eventName")
let eventID = joperate.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:
joperate.timeKeepingEventEnd(eventID, {key:"value"})
joperate.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:
joperate.timeKeepingEventPause(eventID)
joperate.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:
joperate.timeKeepingEventResume(eventID)
joperate.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:
joperate.removeTimeKeepingEvent(eventID)
joperate.removeTimeKeepingEvent(eventID)
This code block is shown in the floating window
Clear all timing events
- clearTimeKeepingEvent()
- Description:
- Clear all timing events.
- Example:
joperate.clearTimeKeepingEvent()
joperate.clearTimeKeepingEvent()
This code block is shown in the floating window
Enter data validation mode
- openDebugMode(param)
- Description:
- Enter data validation mode.
- Example:
// Enter validation mode by scanning a code
wx.scanCode({
success (res) {
let debug = joperate.openDebugMode(res.result)
}
})
// Enter validation mode by scanning a code
wx.scanCode({
success (res) {
let debug = joperate.openDebugMode(res.result)
}
})
This code block is shown in the floating window
Demo APIs
Check Operations Growth activation status
- isValid(completion)
- Description:
- Whether your project has activated Operations Growth.
code = 0means activated. - Example:
joperate.isValid((code, msg)=>{})
joperate.isValid((code, msg)=>{})
This code block is shown in the floating window
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:
joperate.userData((code, data)=>{})
joperate.userData((code, data)=>{})
This code block is shown in the floating window
Get project info
- appInfo(completion)
- Description:
- The callback returns project info.
- Example:
joperate.appInfo((code, data)=>{})
joperate.appInfo((code, data)=>{})
This code block is shown in the floating window
Get current preset properties
- async peripheralData()
- Description:
- Preset property info.
- Example:
jopreate.peripheralData().then(val => {})
jopreate.peripheralData().then(val => {})
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?