React Native SDK 配置方法参考
本参考文档记录了 SingularConfig 类中可用的配置方法。这些方法使用构建器模式创建配置对象,用于初始化 Singular SDK。每个方法都会返回 SingularConfig 对象本身,从而实现方法链。
withClipboardAttribution
SingularConfig.withClipboardAttribution Method
启用基于剪贴板的属性,以便在无法进行深度链接时改进跟踪。
签名
withClipboardAttribution(): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withClipboardAttribution();
withConversionValueUpdatedHandler
SingularConfig.withConversionValueUpdatedHandler Method
设置 SKAdNetwork 转换值更新时调用的处理函数(仅适用于 iOS 14+)。
签名
withConversionValueUpdatedHandler(handler: (value: number) => void): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withConversionValueUpdatedHandler((value) => {
console.log("Conversion value updated to:", value);
// Perform actions based on the new conversion value
});
withConversionValuesUpdatedHandler
SingularConfig.withConversionValuesUpdatedHandler Method
设置 SKAdNetwork 4.0 转换值更新时调用的处理函数(仅限 iOS 16.1+)。
签名
withConversionValuesUpdatedHandler(handler: (fineValue: number, coarseValue: number, lockWindow: boolean) => void): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withConversionValuesUpdatedHandler((fineValue, coarseValue, lockWindow) => {
console.log("Fine value:", fineValue);
console.log("Coarse value:", coarseValue);
console.log("Lock window:", lockWindow);
// Handle updated conversion values
});
withCustomSdid
SingularConfig.withCustomSdid Method
企业功能:设置自定义 SDID(奇异设备 ID),并在设置和接收 ID 时调用回调处理程序。
签名
withCustomSdid(customSdid: string, didSetSdidCallback: (result: string) => void, sdidReceivedCallback: (result: string) => void): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withCustomSdid(
"custom-device-id-12345",
(result) => { console.log("SDID set result:", result); },
(result) => { console.log("SDID received:", result); });
withCustomUserId
SingularConfig.withCustomUserId Method
为当前用户会话设置自定义用户标识符。
签名
withCustomUserId(customUserId: string): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withCustomUserId("user_123456");
withDeviceAttributionCallbackHandler
SingularConfig.withDeviceAttributionCallbackHandler Method
BETA 功能:设置一个处理函数,以便在设备属性数据可用时接收该数据。
签名
withDeviceAttributionCallbackHandler(deviceAttributionCallbackHandler: (attributes: Map<string, any>) => void): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withDeviceAttributionCallbackHandler((attributes) => {
// Process attribution data
console.log("Attributes:", JSON.stringify(Object.fromEntries(attributes)));
// Use attribution data to customize user experience
if (attributes.get("source") === "facebook") {
// Show Facebook-specific welcome message
}
});
withEspDomains
SingularConfig.withEspDomains Method
设置电子邮件归属的 ESP(电子邮件服务提供商)域列表。
签名
withEspDomains(domains: [string]): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withEspDomains([ "mailchimp.com", "sendgrid.net", "klaviyo.com" ]);
withFacebookAppId
SingularConfig.withFacebookAppId Method
设置 Facebook App ID,以改进 Facebook 营销活动的归因。
签名
withFacebookAppId(appId: string): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withFacebookAppId("123456789012345");
withGlobalProperty
SingularConfig.withGlobalProperty Method
设置全局属性,所有发送到 Singular 的事件都将包含该属性。
签名
withGlobalProperty(key: string, value: string, overrideExisting: boolean): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withGlobalProperty("app_version", "1.2.3", true)
.withGlobalProperty("user_tier", "premium", false);
withLimitDataSharing
SingularConfig.withLimitDataSharing Method
配置数据共享限制,以符合隐私法规(如 CCPA)。
签名
withLimitDataSharing(shouldLimitDataSharing: boolean): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withLimitDataSharing(true);
withLimitedIdentifiersEnabled
SingularConfig.withLimitedIdentifiersEnabled Method
启用或禁用有限标识符,以保护隐私。
签名
withLimitedIdentifiersEnabled(limitedIdentifiersEnabled: boolean): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withLimitedIdentifiersEnabled(true);
withLogLevel
SingularConfig.withLogLevel Method
设置 Singular SDK 的日志记录级别。
签名
withLogLevel(level: number): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withLogLevel(3);
withLoggingEnabled
SingularConfig.withLoggingEnabled Method
为调试目的启用详细日志记录。
签名
withLoggingEnabled(): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withLoggingEnabled();
withManualSkanConversionManagement
SingularConfig.withManualSkanConversionManagement Method
启用手动管理 SKAdNetwork 转换(仅限 iOS)。
签名
withManualSkanConversionManagement(): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withManualSkanConversionManagement();
withOAIDCollection
SingularConfig.withOAIDCollection Method
在中国的 Android 设备上收集 OAID 用于归属。
签名
withOAIDCollection(): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withOAIDCollection();
withPushNotificationsLinkPaths
SingularConfig.withPushNotificationsLinkPaths Method
配置推送通知有效载荷中可找到 Singular 链接的路径。
签名
withPushNotificationsLinkPaths(pushNotificationsLinkPaths: [[string]]): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withPushNotificationsLinkPaths([
["data", "singular_link"],
["custom", "tracking_url"]
]);
withSessionTimeoutInSec
SingularConfig.withSessionTimeoutInSec Method
设置会话超时时间(秒)。
签名
withSessionTimeoutInSec(sessionTimeout: number): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withSessionTimeoutInSec(60);
withShortLinkResolveTimeout
SingularConfig.withShortLinkResolveTimeout Method
以秒为单位设置解析短链接的超时时间。
签名
withShortLinkResolveTimeout(shortLinkResolveTimeout: number): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withShortLinkResolveTimeout(10);
withSingularLink
SingularConfig.withSingularLink Method
当用户通过跟踪链接打开应用程序时,配置处理程序以处理 Singular 深度链接。
签名
withSingularLink(handler: (params: SingularLinkParams) => void): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withSingularLink(singularLinkParams => {
const deeplink = singularLinkParams.deeplink;
const passthrough = singularLinkParams.passthrough;
const isDeferred = singularLinkParams.isDeferred;
// Add your deep link handling logic here
if (deeplink && deeplink.includes('product')) {
// Navigate to product page
console.log("Navigating to product from deeplink:", deeplink);
}
// Use passthrough data if available
if (passthrough) {
console.log("Passthrough data:", passthrough);
}
// Check if this was a deferred deep link
if (isDeferred) {
console.log("This was a deferred deep link");
}
});
withSkAdNetworkEnabled
SingularConfig.withSkAdNetworkEnabled Method
启用或禁用 SKAdNetwork 对 iOS 14+ 归因的支持。
签名
withSkAdNetworkEnabled(enabled: boolean): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withSkAdNetworkEnabled(true);
withWaitForTrackingAuthorizationWithTimeoutInterval
SingularConfig.withWaitForTrackingAuthorizationWithTimeoutInterval Method
设置等待用户跟踪授权响应的超时时间间隔(秒)(仅限 iOS 14+)。
签名
withWaitForTrackingAuthorizationWithTimeoutInterval(interval: number): SingularConfig
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withWaitForTrackingAuthorizationWithTimeoutInterval(30);
Complete Configuration Example
Chaining Multiple Configuration Methods
示例显示如何将多个配置方法串联在一起。
使用示例
const config = new SingularConfig("SDK KEY", "SDK SECRET")
.withWaitForTrackingAuthorizationWithTimeoutInterval(30)
.withCustomUserId("user_123456")
.withGlobalProperty("key_1", "value1", true)
.withLimitDataSharing(false)
.withFacebookAppId("123456789012345");
.withSingularLink((params) = {
// Handle deep link parameters
if (params.deeplink) {
console.log("Deep link received:", params.deeplink);
}
})
// Initialize Singular with the configuration
Singular.init(config);