神策分析帮助中心 技术指南 客户端 SDK 广告 SDK Current: iOS SDK 集成(广告 SDK) iOS SDK 集成(广告 SDK) 广告 SDK 用于支持 Apple Search Ads(苹果搜索广告,简称 ASA )激活归因,能够全链路追踪用户的激活与后链路行为,并支持前后链路打通,配合神策广告投放分析产品进行渠道分析;广告 SDK 依赖于神策分析 SDK 2.6.3 及以上版本,在使用前请确保已经成功集成神策分析 SDK,并进行了 SDK 初始化,详情可参考 SDK 集成 (iOS)、SDK 集成(macOS)。 1. 集成步骤 CocoaPods 方式 源码方式 在 Podfile 文件中添加 pod 'SensorsAdvertising' 打开终端,切换到项目目录执行 pod install 或 pod update SensorsAdvertising注:如果执行 pod update 无法检测到最新版本,可以先执行 pod cache clean SensorsAdvertising 清除本地缓存。 从 GitHub 获取 SDK 的源代码 ;将 SDK(SensorsAdvertising → SensorsAdvertising 中的 SensorsAdvertising.framework )导入 App 项目,并选中 Copy items if needed。 2. 使用步骤2.1. 添加 IDFA 授权描述信息在 info.plist 文件中添加 NSUserTrackingUsageDescription 授权描述信息2.2. 导入头文件在 AppDelegate.m 文件中导入 SensorsAdvertising 头文件 #import <SensorsAdvertising/SensorsAdvertising.h> CODE 2.3. 初始化 SDK - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 初始化 SensorsAnalytics SDK NSString *serverURL = @"http://xxxxx"; SAConfigOptions *saconfigOptions = [[SAConfigOptions alloc] initWithServerURL:serverURL launchOptions:launchOptions]; saConfigOptions.autoTrackEventType = SensorsAnalyticsEventTypeAppStart | SensorsAnalyticsEventTypeAppEnd | SensorsAnalyticsEventTypeAppClick | SensorsAnalyticsEventTypeAppViewScreen; saConfigOptions.enableLog = YES; [SensorsAnalyticsSDK startWithConfigOptions:saConfigOptions]; // 初始化 SensorsAdvertising SDK SADConfigOptions *sadconfigOptions = [[SADConfigOptions alloc] initWithLaunchOptions:launchOptions]; // sadconfigOptions 配置 // ... [SensorsAdvertising startWithConfigOptions:sadconfigOptions]; // 其他业务处理 // ... return YES; } CODE 注意 广告 SDK 依赖 SensorsAnalyticsSDK,因此需要先初始化 SensorsAnalyticsSDK广告 SDK 会自动采集激活事件,原激活事件接口禁止手动调用若原记录的激活事件名不是 $AppInstall,需要使用虚拟事件将原激活事件和 $AppInstall 合并分析数据,具体咨询值班同学原激活事件接口参数,通过 SADConfigOptions 进行配置appInstallProperties 激活事件中自定义属性disableAppInstallCallback 激活事件关闭渠道匹配的回调请求 2.4. autoRequestTrackingAuthorization广告 SDK 默认会进行请求 IDFA 授权,若不想让 SDK 自动请求 IDFA 授权,可配置 autoRequestTrackingAuthorization = NO;autoRequestTrackingAuthorization = NO 时,必须调用广告 SDK 接口,将授权状态传递给 SDK。 - (void)applicationDidBecomeActive:(UIApplication *)application { if (@available(iOS 14, *)) { [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { [SensorsAdvertising.sharedInstance setTrackingAuthorizationStatus:status]; }]; } } CODE 注意 setTrackingAuthorizationStatus: 接口必须在 SensorsAdvertising SDK 初始化以后调用 注:本文档内容为神策产品使用和技术细节说明文档,不包含适销类条款;具体企业采购产品和技术服务内容,以商业采购合同为准。