【ABTest】一款简单易用的ABTest开源库

Github : https://github.com/TJHello/ABTest
Gitee: https://gitee.com/TJHello/ABTest

ABTest

一款简单易用的ABTest开源库

原理:通过给事件标签,添加A,B后缀来统计ABTest结果。

1、兼容友盟、Firebase,可同时打点。

2、支持在线配置ABTest。

3、支持统计留存。

4、支持统计使用时长。

使用步骤

Step1 接入自动集成插件到build.gradle(project)

buildscript {
     repositories {
        ...
         maven { url 'https://raw.githubusercontent.com/TJHello/publicLib/master'}
     }
}

allprojects {
     repositories {
        ...
        maven { url 'https://raw.githubusercontent.com/TJHello/publicLib/master'}
     }
}

Step2 配置build.gradle(app)

dependencies {
    //需要另外接入友盟或者Firebase打点
    implementation 'com.TJHello:ABTest:1.0.17'
}

Step3 配置Application

override fun onCreate() {
    super.onCreate()
    val isNew = true//自己判断当前用户是否是新用户,如果一开始就接入了ABTest,可以写成true。
    ABTest.isDebug = true
    //本地测试
    ABTest.init(this, true)
        .addTest(ABConfig().apply {//添加一项ABTest
            this.name = "ABTestDemo"//测试名称
            this.ver = 0//AB测试版本,默认0,如果同一个测试不同版本,则修改这个数值
            this.abVer = 10001//当前测试对应的应用版本号
            this.data = mutableListOf("1","2")//支持任意多维度的数据
            this.listenEvent = mutableListOf("ABTestDemoEvent")//需要纳入AB的事件,留空则监听所有事件
            this.mergeEvent = false//合并事件(测试中)
            this.mergeTag = true//合并标签eg:data_A=value1,data_B=value2  ->  data = value1_A,data = value2_B
            this.onlyNew = true//仅将新增用户纳入测试结果
        })
    //通过Firebase-RemoteConfig在线配置ABTest(需要另外接入该库)
    ABTest.init(this, true)
    RemoteConfig.init(){
        if(it){
            ABTest.addTestByRemoteConfig()
        }    
    }
    //通过自己的服务器在线配置ABTest
    ABTest.init(this, true)
    ABTest.addTestByJsonConfig(xx)
    ABTest.addTestByInfoConfig()
}

Step4 替换友盟打点

其余友盟初始方法不变,替换友盟onEvent方法

//MobclickAgent.onEvent(context, eventId, map)

ABTest.getInstance().event(eventId,map)

日志查看 tag : ABTestLog

打点效果

未接入ABTest前->

data
1
2
3

接入ABTest后->

datadata_Test_Adata_Test_Bdata_Test_Cdata_Test_D
11111
22222
33333
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Implementing an A/B testing system in Java can be done in a few steps. 1. Define the experiment: Start by clearly defining the experiment and its goals. What are you trying to test? What are the variables you are trying to measure? 2. Create a control group: Next, you'll need to create a control group. This is the group that will not receive any treatment and will serve as a baseline for comparison. 3. Create a treatment group: After creating the control group, create a treatment group. This group will receive the treatment that you want to test. 4. Randomly assign users: Once you have created the control and treatment groups, you'll need to randomly assign users to each group. This is important to ensure that the results are representative and not biased. 5. Collect data: Once the experiment is underway, you'll need to collect data on the variables you're interested in. This could be things like conversion rates, page views, or user engagement. 6. Analyze the results: Finally, you'll need to analyze the results of the experiment. This will involve comparing the results of the control group to the treatment group to see if there is a statistically significant difference. Here is an example of a simple A/B testing system in Java: ``` import java.util.Random; public class ABTest { public static void main(String[] args) { int controlCount = 0; int treatmentCount = 0; Random random = new Random(); for (int i = 0; i < 1000; i++) { boolean isControl = random.nextBoolean(); if (isControl) { controlCount++; } else { treatmentCount++; } } System.out.println("Control group count: " + controlCount); System.out.println("Treatment group count: " + treatmentCount); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值