Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add abtesting module #281

Merged
merged 31 commits into from
Dec 25, 2023
Merged

feat: add abtesting module #281

merged 31 commits into from
Dec 25, 2023

Conversation

YoloMao
Copy link
Collaborator

@YoloMao YoloMao commented Oct 11, 2023

No description provided.

@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

Attention: 34 lines in your changes are missing coverage. Please review.

Comparison is base (5f9bb1c) 82.70% compared to head (a2c0d23) 83.20%.

Files Patch % Lines
Modules/ABTesting/GrowingABTesting.m 92.19% 11 Missing ⚠️
Modules/WebCircle/GrowingWebCircle.m 80.00% 5 Missing ⚠️
...Node/Category/UINavigationController+GrowingNode.m 0.00% 2 Missing ⚠️
...ore/GrowingNode/Category/UITableView+GrowingNode.m 80.00% 2 Missing ⚠️
GrowingTrackerCore/Event/GrowingEventManager.m 0.00% 2 Missing ⚠️
...TrackerCore/Network/Request/GrowingNetworkConfig.m 75.00% 2 Missing ⚠️
...dules/ABTesting/Request/GrowingABTRequestAdapter.m 90.90% 2 Missing ⚠️
Modules/Hybrid/GrowingWKWebViewJavascriptBridge.m 60.00% 2 Missing ⚠️
...rCore/GrowingNode/Category/UIControl+GrowingNode.m 85.71% 1 Missing ⚠️
GrowingAutotrackerCore/GrowingRealAutotracker.m 75.00% 1 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #281      +/-   ##
==========================================
+ Coverage   82.70%   83.20%   +0.50%     
==========================================
  Files         136      141       +5     
  Lines        9640     9999     +359     
==========================================
+ Hits         7973     8320     +347     
- Misses       1667     1679      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@YoloMao
Copy link
Collaborator Author

YoloMao commented Oct 16, 2023

模块集成

Cocoapods 集成

  1. 使用 Cocoapods 安装
pod 'GrowingAnalytics/ABTesting'

打开终端,切换到项目目录,执行 pod installpod update

  1. 在 AppDelegate.m 中导入 #import "GrowingABTesting.h"

Swift Package Manager 集成

  1. 添加 GrowingModule_ABTesting Package

  2. 在 AppDelegate.swift 中导入 import GrowingModule_ABTesting

模块配置

ABTesting 模块中提供了相关配置:

配置接口 参数类型 是否必填 默认值 说明
abTestingRequestInterval NSUInteger 5 单个实验 TTL 时长,超出 TTL 时获取对应实验则重新请求;单位分钟
abTestingServerHost NSString nil ABTesting 配置地址,示例:https://n.datayi.cn
networkConfig.abTestingRequestTimeout NSTimeInterval 5 ABTesting 获取实验配置的请求超时时间;单位秒
GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithProjectId:@"YourAccountId"];
configuration.dataCollectionServerHost = @"YourServerHost";
configuration.dataSourceId = @"YourDatasourceId";

// ABTesting 配置地址
configuration.abTestingServerHost = @"https://n.datayi.cn";
// 单个实验 TTL 时长
configuration.abTestingRequestInterval = 5;
// 获取实验配置的请求超时时间
GrowingNetworkConfig *networkConfig = [GrowingNetworkConfig config];
networkConfig.abTestingRequestTimeout = 2.0f;
configuration.networkConfig = networkConfig;

[GrowingAutotracker startWithConfiguration:configuration launchOptions:launchOptions];

获取实验配置

根据传入的 layerId,获取实验配置变量

+ (void)fetchExperiment:(NSString *)layerId completedBlock:(void (^)(GrowingABTExperiment *_Nullable))completedBlock;
参数 参数类型 是否必填 默认值 说明
layerId NSString nil 实验层 id
completedBlock void (^)(GrowingABTExperiment *_Nullable) nil 根据返回的 experiment 判断,若 experiment 为 nil,则为请求失败,请按需重试;
若 experiment.experimentId 或 experiment.strategyId 为 nil,则未命中实验
[GrowingABTesting fetchExperiment:@"123456" completedBlock:^(GrowingABTExperiment * _Nullable experiment) {
    if (!experiment) {
        // 请求失败
        return;
    }
    if (experiment.experimentId.length > 0 && experiment.strategyId.length > 0) {
        // 命中实验
        // 获取实验配置参数
        NSDictionary *variables = experiment.variables;
    } else {
        // 未命中实验
    }
}];

@YoloMao YoloMao force-pushed the feat/abtest branch 2 times, most recently from efacaed to 1575336 Compare October 26, 2023 07:03
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

5 New issues
0 Security Hotspots
93.2% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@YoloMao YoloMao merged commit 2d3950f into master Dec 25, 2023
5 checks passed
@YoloMao YoloMao deleted the feat/abtest branch December 25, 2023 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants