Skip to main content

Native

Integration Guide

The current version only supports mini program projects developed using the official WeChat/Douyin/mPaaS Developer Tools.

  • For WeChat Mini Program integration: Unzip BonreeSDK_TDEM_MP_Wechat.zip and add BonreeSDK_MP_Wechat.min.js to your project;
  • For Douyin Mini Program integration: Unzip BonreeSDK_TDEM_MP_Tiktok.zip and add BonreeSDK_MP_Tiktok.min.js to your project;
  • For mPaaS Mini Program integration: Unzip BonreeSDK_TDEM_MP_mPaaS.zip and add BonreeSDK_MP_mPaaS.min.js to your project.

The WeChat Mini Program integration is illustrated below (other platforms follow the same pattern):

image

  • For public cloud platform usage: Add the data reporting domain to the server domain whitelist in the WeChat/Douyin/mPaaS Mini Program Admin Console. The example shows adding the public cloud data reporting domain https://oneupload.bonree.com in the WeChat Mini Program Admin Console. For private deployment environments, configure the domain according to your actual deployment or contact technical support.

image

Implementation

  • Import the agent file in app.js:

    For WeChat Mini Programs:

    const BonreeSDK = require('./BonreeSDK_MP_Wechat.min.js')

    For Douyin Mini Programs:

    const BonreeSDK = require('./BonreeSDK_MP_Tiktok.min.js')

    For mPaaS Mini Programs:

    const BonreeSDK = require('./BonreeSDK_MP_mPaaS.min.js')
  • Initialize the mini program agent by setting the Config address and AppID in the configuration parameters:

<#Config Address#> and <#AppID#> can be obtained from the platform. Refer to How to Query AppID and Config Address? for details. Contact technical support if needed.

const BRSAgent = BonreeSDK.start({
configAddress: "<#Config Address#>",
appId: "<#AppID#>"
})
  • For WeChat/Douyin Mini Programs, export the SDK instance for use in other files:
module.exports = BRSAgent // Supports WeChat and Douyin Mini Programs

WeChat/Douyin Mini Program example:

// app.js
const BonreeSDK = require('./BonreeSDK_MP_Wechat.min.js') // WeChat Mini Program
// const BonreeSDK = require('./BonreeSDK_MP_Tiktok.min.js')// Douyin Mini Program

const BRSAgent = BonreeSDK.start({
configAddress: '<#Config Address#>',
appId: '<#AppID#>',
})
module.exports = BRSAgent

App({
onLaunch() {
// App launch logic
},
onShow() {
// App show logic
},
globalData: {}
})
  • For mPaaS, due to sandbox restrictions on global object access, you need to mount the SDK instance to the global scope for use in other files:
// app.js
App({
onLaunch() {
// Mount to the App global object
this.BRSAgent = BRSAgent;
},
onShow() {

},
});

mPaaS Mini Program example:

// app.js
const BonreeSDK = require('./BonreeSDK_MP_mPaaS.min.js')

const BRSAgent = BonreeSDK.start({
configAddress: '<#Config Address#>',
appId: '<#AppID#>',
})

App({
onLaunch() {
// Mount to the App global object
this.BRSAgent = BRSAgent;
},
onShow() {

},
});

After running, check the Network in the WeChat/Douyin/mPaaS Developer Tools debugger. If there is a config request result output and the rc field in the response is 10000, it indicates successful integration. The following figure shows an example of the response result in WeChat Developer Tools:

image