MZAnalytics_IOS_SDK部署指南

1、适用范围

MZAnalytics_IOS_SDK适用于 iOS 8-iOS 14.0,请将iOS Deployment Target设置为iOS 8.0

2、集成准备

为应用申请App ID

在 http://tongji.cn.miaozhen.com 网站中创建一款应用,
您将获得一串随机的“dc-”开头的数字ID,用于唯一标识您的一款应用。

AppID说明

appId为应用追踪的唯一标识,在站点信息内获取。

3、集成SDK

  1. 在创建的应用内下载移动端 iOS SDK。
  2. 将文件MZAnalytics_IOS_SDK.frameworksdkconfig.xml导入到app项目中,添加过程中注意确保在弹出的界面中勾选Copy items into destination group's folder(if needed),并确保Add To Targets 勾选相应的Target。
  3. 添加依赖库,在Xcode选择 TARGETS-->Build Phases-->Link Binary With Libraries--> + 添加以下framework框架:

    SystemConfiguration.framework AdSupport.framework Foundation.framework libxml2.2.tbd AppTrackingTransparency.framework

  4. 添加编译参数,选择 TARGETS-->Build Settings-->Other Linker Flags,设置为-ObjC。必须添加该参数,否则会引起崩溃。

4、初始化SDK

在AppDelegate.m文件中导入#import <MZAnalytics_IOSVx.x.x_SDK/MLTSiteSDK.h>,
 并在application: didFinishLaunchingWithOptions:方法中,调用SDK初始化方法。

接口定义:

+ (MLTSiteManager *)sharedInstanceWithAppId:(NSString *)appId;

参数说明

参数 类型 说明
AppId NSString 网站创建站点时的站点id为您的AppId。

示例代码

[MLTSiteManager sharedInstanceWithAppId:@"xxxx"]; //使用时将xxxx替换为实际的AppId

5、页面监测

接口定义:

- (void)trackPageView:(NSString *)title appendCustomDimMetrics:(nullable NSDictionary *)CustomDimMetrics;

参数说明:

参数 类型 说明
title NSString 页面名称 (必填)

示例代码:

//页面监测
[[MLTSiteManager shareInstance] trackPageView:@"首页" appendCustomDimMetrics:nil];

备注:实际使用时将【首页】替换为实际的页面标题。

6、基础事件监测

接口定义:

- (void)trackEvent:(NSString *)eventClassify eventAction:(NSString *)eventAction 
 eventTag:(NSString *)eventTag eventPrice:(NSInteger)eventPrice 
 appendCustomDimMetrics:(nullable NSDictionary *)CustomDimMetrics;

参数说明:

参数 类型 说明
eventClassify NSString 事件分类(选填)
eventAction NSString 事件动作(选填)
eventTag NSString 事件标签(选填)
eventPrice NSInteger 事件价值(选填)

示例代码:

//自定义事件
[[MLTSiteManager shareInstance] trackEvent:@"点击热门banner" 
eventAction:@"Click" eventTag:@"点击"
eventPrice:10 appendCustomDimMetrics:nil];

备注:事件分类、事件动作、事件标签 需至少填写一个。

7、自定义事件

接口定义:

 - (void)trackSiteCustomEvent:(NSDictionary *)customEvent 
 appendCustomDimMetrics:(nullable NSDictionary *)CustomDimMetrics;

参数说明:

参数 类型 说明
customEvent NSDictionary 包含自定义事件id、以及自定义事件维度、指标数均以实际在 系统中创建的自定义事件为准。
customDimMetrics NSDictionary 自定义维度和指标(可选)

示例代码:

//自定义事件  没有自定义维度时,customDimMetrics传nil。
[[MLTSiteManager shareInstance] trackSiteCustomEvent:
@{@"customActionId":@"1",
@"customActionLabel1":@"2020/01/10",
@"customActionLabel2":@"15728749249", 
@"customActionLabel3":@"北京",
@"customActionValue1":@"1"} 
appendCustomDimMetrics:
@{@"customDimension1":@"点击信用卡",
@"customDimension2":@"查看商品详情",
@"customMetrics1":@"点击信用卡总用户数",
@"customMetrics2":@"查看商品详情总用户数"}];

备注: 自定义事件ID必传,其他自定义事件维度至少传一个。 customActionLabel最多20个,名称为customActionLabel1~20。 customActionValue最多20个,名称为customActionValue1~20。 customDimension最多100个,名称为customDimension1~100。 customMetrics最多25个,名称为customMetrics1~25。

实际使用时将自定义事件维度、自定义事件指标、自定义维度、自定义指标替换为实际回传值。

8、页面隐藏或关闭(关闭页面或进入后台时调用)

接口定义:

- (void)trackPulse;

参数说明:

示例代码:

//页面隐藏或关闭(关闭页面或进入后台时调用)
[[MLTSiteManager shareInstance] trackPulse];

9、获取访客id(设备唯一ID)

接口定义:

+ (NSString *)getCid;

参数说明:

示例代码:

[MLTSiteManager getCid];

10、打印日志

接口定义:

+ (void)setEnableLog:(BOOL)isEnableLog;

参数说明:

参数 类型 说明
isEnableLog BOOL 是否打印日志,默认为NO

示例代码:

[MLTSiteManager setEnableLog:YES];

接口定义:

+(void)handleOpenURL:(NSURL *)url;

参数说明:

参数 类型 说明
url NSURL 回调接收到的url (必填)

示例代码:

在AppDelegate.m的deeplink系统回调中现实本方法, 根据项目配置如下:

/**DeepLink */
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url 
    options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{

     [MLTSiteManager  handleOpenURL:url];

    return YES;
    }

/**UniversalLinks */
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{

    [MLTSiteManager handleOpenURL:userActivity.webpageURL];        

    return YES;
    }
唤起链接说明
示例:
    mltsite://event/page/view/last?name=ceshi&age=30&mz_ca=2220134&mz_sp=35790
格式规范:
    scheme://host/path?key1=value1&key2=value2&mz_ca=2220134&mz_sp=35790
说明:
    1、问号?前面客户可以自己定义
    2、问号后面key和value连接必须用=,不同key-value拼接必须用&
    3、同时存在mz_ca和mz_sp归为deeplink流量,否则归为普通流量
    4、mz_ca合法是7位,mz_sp合法是5位

12、配置SDKConfig权限(根据业务需求自行配置)

项目中 sdkconfig.xml 为sdk idfa权限开关配置文件,可以通过配置isRequired的value控制idfa的采集。 a. 当设置idfa的isRequired的value为true时,获取idfa; b. 当设置idfa的isRequired的value为false时,不获取idfa;

举例:以下部分是如何在sdkconfig.xml文件中配置是否采集idfa的示例。

//采集idfa的配置示例`<argument>`
    `<key>`idfa`</key>` // 该开关控制的是idfa的采集
    `<value>`z`</value>`
    `<urlEncode>`true`</urlEncode>`
    `<isRequired>`true`</isRequired>` //idfa的 isRequired的value为true,表示sdk会采集idfa
`</argument>`

//不采集idfa的配置示例`<argument>`
    `<key>`idfa`</key>` // 该开关控制的是idfa的采集
    `<value>`z`</value>`
    `<urlEncode>`true`</urlEncode>`
    `<isRequired>` false `</isRequired>` //idfa的 isRequired的value为false,表示sdk不会采集idfa
`</argument>`

13、验证和调试

  1. 参数是否齐全。
  2. 请求次数和第三方监测平台是否能对应上。

请联系第三方监测平台完成测试。

results matching ""

    No results matching ""