小程序 oCPC 埋码升级

最后更新时间:2019.03.20

百度智能小程序已经支持 oCPC 转化数据采集,旧版的 SDK 会逐步下线,不再维护, 若您还在使用旧版的 SDK 请按照此文档尽快完成升级

引入部分

现在的引入方式

通过npm安装angelia-swan

npm install angelia-swan

原来的引入方式

下载SDK文件(fcbuf.js)到app.js同级的文件夹目录下

初始化部分

现在的初始化方式

app.js中引用后直接初始化(请勿重复初始化),不需要额外参数

const angelia = require('angelia-swan');
// 直接初始化,只需要在此初始化一次,请勿对SDK重复初始化
angelia.init();

App({
    onLaunch(e) {
    },

    onShow(e) {
    }
});

原来的初始化方式

ApponShow阶段初始化,并传onShow的事件参数

// 在同级的app.js中这么引用
const fcbuf = require('./fcbuf');
// 在pages/demo/demo.js中这么引用
// const fcbuf = require('../../fcbuf');

App({
    onLaunch(e) {
    },

    onShow(e) {
        // 将onShow的参数传入给SDK
        fcbuf.init(e);
    }
});

调用API回传部分

现在的接口方式

在需要回传数据的地方调用新SDK的log接口(注意:接口参数结构有变)

// /pages/demo/demo.js

const angelia = require('angelia-swan');

Page({
    formSubmitHandle: function(e) {
        swan.request({
            url: 'http://you.service.com/api/order',
            method: 'POST',
            data: '{"actid": "xxx", "item": "candies", "amount": 20}',
            header: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            success: res => {
                // 在请求成功的回调方法里回传转化数据
                angelia.log({
                    // 这里的3代表的是「表单提交成功」这一转化类型
                    // 如果需要回传其它类型的转化数据,这里应换成其它值
                    convertType: 3
                });
                swan.showToast({
                    title: "下单成功"
                })
            },
            fail: err => {
                swan.showToast({
                    title: "服务异常"
                });
            }
        });
    }
});

原来的接口方式

在需要回传数据的地方调用submit接口

// /pages/demo/demo.js

const fcbuf = require('../../fcbuf.js');

Page({
    formSubmitHandle: function(e) {
        swan.request({
            url: 'http://you.service.com/api/order',
            method: 'POST',
            data: '{"actid": "xxx", "item": "candies", "amount": 20}',
            header: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            success: res => {
                // 在请求成功的回调方法里回传转化数据
                fcbuf.submit({
                    // 这里的3代表的是「表单提交成功」这一转化类型
                    // 如果需要回传其它类型的转化数据,这里应换成其它值
                    t: 3
                });
                swan.showToast({
                    title: "下单成功"
                })
            },
            fail: err => {
                swan.showToast({
                    title: "服务异常"
                });
            }
        });
    }
});

results matching ""

    No results matching ""