更新记录

1.0.1(2025-07-02)

更新插件说明文档等

1.0.0(2025-07-02)

首次发布插件


平台兼容性

uni-app

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
- - - - 5.0 × ×
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - -

uni-app x

Chrome Safari Android iOS 鸿蒙 微信小程序
- - 5.0 × × -

Singular,Singular插件,Singular移动归因(插件有问题请***:1684729125)

插件仅支持Android版本

插件提供的方法 -- 详情请参考官网文档及demo

相关文档

Singular开发文档
Singular官方网址

插件说明

  • 回调方法说明,回调是一个对象,内容如下:
    • code:结果码,200表示成功,400表示失败
    • msg:执行方法成功或失败的提示内容
    • data:执行返回的数据,可为任意类型的数据,也可能为空,根据每个方法不同

引用插件

import {
    initSingularAndDeeplink,
    logEventJSON,
    logEvent,
    revenue,
    customRevenue,
    setCustomUserID,
    setGlobalProperty
} from "@/uni_modules/gt-singular"

使用插件代码如下,更多代码请参考Demo

/**
 * 初始化SDK并监听Deeplink
 * 
 * 插件其他方法,需要时此方法后执行
 * 
 * 有新的Deeplink时,会一直在initSingularAndDeeplink回调中返回
 * 
 * {  deeplink:'',passthrough:'',isDeferred:true }
 * 
 */
doInitSingularAndDeeplink() {
    initSingularAndDeeplink({
        sdkKey: 'biaibiai_fec357e8',
        sdkSecret: '1ac427fdb9b4e126de8f566f27420483'
    }, res => {
        console.log('initSingularAndDeeplink callback: ', res);
        if (res.code == 200) {
            this.listDeepLink.push(JSON.stringify(res.data))
        } else {
            this.showToast(res.msg || 'initSingularAndDeeplink出错!')
            console.log('initSingularAndDeeplink error: ', res);
        }
    });
    this.showToast("init succeed.")
},

/**
 * 设置用户id
 */
doSetCustomUserID() {
    setCustomUserID('gui0001',ret => {
        console.log("setCustomUserID ret: ",ret)
        this.showToast(ret.msg)
    });
},

/**
 * 设置全局属性
 * 应用一共最多可以定义5 个全局属性
 */
doSetGlobalProperty() {
    this.showLoading();
    setGlobalProperty({
        propertyKey: 'favorite_food',
        propertyValue: 'litchi',
        overrideExisting: false //如果propertyKey已经被设置,是否覆盖现有值
    }, res => {
        uni.hideLoading();
        this.showToast(res.msg)
        if (res.code == 200) {
            console.log('setGlobalProperty success: ', res);
        } else {
            console.log('setGlobalProperty failed: ', res);
        }
    });
},

/**
 * 报告记录用户事件
 */
doLogEvent() {
    this.showLoading();
    logEvent({
            eventName: 'sng_tutorial_complete',
            eventParams: { //eventParams可以不传,key-value值对应附加信息的key-value
                sng_attr_content: '1',
                sng_attr_content_id: "001",
                sng_attr_content_type: 1,
                sng_attr_success: true
            }
        },
        res => {
            uni.hideLoading();
            this.showToast(res.msg)
            if (res.code == 200) {
                console.log('logEvent success: ', res);
            } else {
                console.log('logEvent failed: ', res);
            }
        }
    );
},
/**
 * 报告记录用户事件2
 */
logEventJSON() {
    this.showLoading();
    logEventJSON({
            eventName: 'sng_tutorial_complete2',
            eventParams: { //eventParams可以不传,key-value值对应附加信息的key-value
                sng_attr_content: '22',
                sng_attr_content_id: "002",
                sng_attr_content_type: 1,
                sng_attr_success: true
            }
        },
        res => {
            uni.hideLoading();
            this.showToast(res.msg)
            if (res.code == 200) {
                console.log('logEventJSON success: ', res);
            } else {
                console.log('logEventJSON failed: ', res);
            }
        }
    );
},

/**
 * 收入跟踪--非订阅应用内购买
 */
doRevenue() {
    this.showLoading();
    revenue({
            currency: "USD", //货币
            amount: 100.89, //金额,支持小数
            // 下面参数1,2,3是三选一的,全部都存在,优先级也是1,2,3。也可以三个参数都不传
            // 参数1
            // purchase: {}, //谷歌账单库收到的购买对象,应该是支付成功返回的信息,详情参考SDK文档
            // 参数2,对象里面的数据可以修改
            attributes: {
                product_id: 'com.gui.singular',
                transaction_id: 'T12345',
                quantity: 1,
                is_trial: false,
            },
            // 参数3,下面这些key是固定的,不能更改
            productSKU: 'SKU1928375',
            productName: 'Reservation Fee',
            productCategory: 'Fee',
            productQuantity: 1,  //整数
            productPrice: 100.56  //支持小数
        },
        res => {
            uni.hideLoading();
            this.showToast(res.msg)
            if (res.code == 200) {
                console.log('revenue success: ', res);
            } else {
                console.log('revenue failed: ', res);
            }
        }
    );
},

/**
 * 收入跟踪--自定义名字,可用于订阅和非订阅。
 * 
 * 订阅的需要使用谷歌支付插件的doQueryPurchases查询subs的历史订单
 * 拿到返回的list数据,再去调用customRevenue方法,传参方法使用参数2的方式
 */
doCustomRevenue() {
    this.showLoading();
    customRevenue({
            eventName: 'MyCustomRevenue',
            currency: "USD", //货币
            amount: 200.54, //金额
            // 下面参数1,2,3是三选一的,全部都存在,优先级也是1,2,3。也可以三个参数都不传
            // 参数1
            // purchase: {}, //谷歌账单库收到的购买对象,应该是支付成功返回的信息,详情参考SDK文档
            // 参数2,对象里面的数据可以修改
            attributes: {
                product_id: 'com.app.test',
                transaction_id: 'T123451111',
                quantity: 2,
                is_trial: true,
            },
            // 参数3,下面这些key是固定的,不能更改
            productSKU: 'SKU1928375111',
            productName: 'Reservation Fee111',
            productCategory: 'Fee11',
            productQuantity: 1,
            productPrice: 1000.99
        },
        res => {
            uni.hideLoading();
            this.showToast(res.msg)
            if (res.code == 200) {
                console.log('customRevenue success: ', res);
            } else {
                console.log('customRevenue failed: ', res);
            }
        }
    );
}

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问