iOS SDK - メソッドリファレンス

iOS SDK - メソッドリファレンス

この包括的なリファレンスでは、iOSアプリケーション向けSingular SDKで使用可能なすべてのメソッドを文書化しています。このSDKは、初期化、イベントトラッキング、収益レポート、アトリビューション、データプライバシー対応、および設定のための機能を提供します。各メソッドには説明、シグネチャ、および実用的な使用例が記載されており、開発者がSingular SDKの機能をアプリケーションに統合するのに役立ちます。

adRevenue

Singular.adRevenue メソッド

詳細な広告データ情報を使用して広告収益イベントをトラッキングします。このメソッドを使用すると、アプリケーションに表示された広告から生成された収益を、さまざまなパラメータで分類し、広告パフォーマンスを分析するために報告できます。

シグネチャ

+ (void)adRevenue:(SingularAdData *)adData;

使用例

Swift Objective-C
// Create ad data object
let adData = SingularAdData(adPlatform: "AdMob",
                            withCurrency: "USD",
                            withRevenue: 0.05)
adData.adUnitId = "ca-app-pub-123456789/1234567890"
adData.adType = "Rewarded"
adData.adPlacementName = "level_complete"

// Track ad revenue event
Singular.adRevenue(adData)

clearGlobalProperties

Singular.clearGlobalProperties メソッド

以前に設定されたすべてのグローバルプロパティを削除します。これは、ユーザーがアプリケーションからログアウトした場合など、グローバルプロパティをリセットする必要がある場合に役立ちます。

シグネチャ

+ (void)clearGlobalProperties;

使用例

Swift Objective-C
// Clear all global properties
Singular.clearGlobalProperties()

createReferrerShortLink

Singular.createReferrerShortLink メソッド

共有およびアトリビューションに使用できるリファラー情報付きの短縮リンクを作成します。このメソッドは、ユーザーと共有できるトラッキング可能なリンクを生成し、特定のリファラルソースに対してインストールやアクティビティをアトリビューションできるようにします。

シグネチャ

+ (void)createReferrerShortLink:(NSString *)baseLink
                   referrerName:(NSString *)referrerName
                     referrerId:(NSString *)referrerId
              completionHandler:(void (^)(NSString *, NSError *))completionHandler;

+ (void)createReferrerShortLink:(NSString *)baseLink
                   referrerName:(NSString *)referrerName
                     referrerId:(NSString *)referrerId
              passthroughParams:(NSDictionary *)passthroughParams
              completionHandler:(void (^)(NSString *, NSError *))completionHandler;

使用例

Swift Objective-C
// Create a short link for referral
Singular.createReferrerShortLink("https://sample.sng.link/B4tbm/v8fp",
                                 referrerName: "John Doe",
                                 referrerId: "aq239897",
                                 passthroughParams: [
                                     "channel": "sms",
                                     "campaign": "summer_promo"
                                 ]) { link, error in
    if let error = error {
        print("Error creating short link: \(error)")
    } else if let link = link {
        print("Generated short link: \(link)")
        // Share the link with users
    }
}

customRevenue

Singular.customRevenue メソッド

指定されたイベント名、通貨、金額、およびオプションの商品情報を使用してカスタム収益イベントをトラッキングします。これにより、カスタムイベント名を使用してより具体的な収益トラッキングが可能になります。

シグネチャ

+ (void)customRevenue:(NSString *)eventname
          transaction:(id)transaction;

+ (void)customRevenue:(NSString *)eventname
          transaction:(id)transaction
       withAttributes:(NSDictionary *)attributes;

+ (void)customRevenue:(NSString *)eventname
             currency:(NSString *)currency
               amount:(double)amount;

+ (void)customRevenue:(NSString *)eventname
             currency:(NSString *)currency
               amount:(double)amount
       withAttributes:(NSDictionary *)attributes;

+ (void)customRevenue:(NSString *)eventname
             currency:(NSString *)currency
               amount:(double)amount
           productSKU:(NSString *)productSKU
          productName:(NSString *)productName
      productCategory:(NSString *)productCategory
      productQuantity:(int)productQuantity
         productPrice:(double)productPrice;

+ (void)customRevenue:(NSData *)transactionJsonRepresentation
      productJsonRepresentation:(NSData *)productJsonRepresentation;

+ (void)customRevenue:(NSString *)eventName
      transactionJsonRepresentation:(NSData *)transactionJsonRepresentation
      productJsonRepresentation:(NSData *)productJsonRepresentation;

+ (void)customRevenue:(NSString *)eventName
      transactionJsonRepresentation:(NSData *)transactionJsonRepresentation
      productJsonRepresentation:(NSData *)productJsonRepresentation
      withAttributes:(NSDictionary *)attributes;

使用例

Swift Objective-C
// Track a custom revenue event
Singular.customRevenue("premium_subscription",
                       currency: "USD",
                       amount: 9.99)

// Track a custom revenue event with attributes
Singular.customRevenue("in_app_purchase",
                       currency: "USD",
                       amount: 5.99,
                       withAttributes: [
                           "product_id": "com.app.gems_pack_small",
                           "quantity": 1
                       ])

// Track a custom revenue event from a StoreKit transaction
if let transactionData = transaction.payment.requestData,
   let productData = try? JSONSerialization.data(withJSONObject: [
       "productID": transaction.payment.productIdentifier
   ]) {
    Singular.customRevenue("in_app_purchase",
                           transactionJsonRepresentation: transactionData,
                           productJsonRepresentation: productData,
                           withAttributes: ["source": "store"])
}

event

Singular.event メソッド

指定された名前とオプションのカスタム属性を使用してイベントをトラッキングします。これらのメソッドを使用して、アプリケーション内のユーザーアクションとエンゲージメントをトラッキングしてください。

シグネチャ

+ (void)event:(NSString *)name;

+ (void)event:(NSString *)name withArgs:(NSDictionary *)args;

+ (void)eventWithArgs:(NSString *)name, ...;

使用例

Swift Objective-C
// Track a simple event
Singular.event("level_completed")

// Track an event with additional parameters
Singular.event("level_completed", withArgs: [
    "level_id": 5,
    "score": 12500,
    "time_spent": 120,
    "difficulty": "medium"
])

getGlobalProperties

Singular.getGlobalProperties メソッド

現在設定されているすべてのグローバルプロパティを取得します。このメソッドは、SDKに設定されているすべてのグローバルプロパティを含むディクショナリを返します。

シグネチャ

+ (NSDictionary *)getGlobalProperties;

使用例

Swift Objective-C
// Get all global properties
let properties = Singular.getGlobalProperties()
print("Global properties: \(properties)")

getLimitDataSharing

Singular.getLimitDataSharing メソッド

現在のデータ共有制限ステータスを取得します。このメソッドは、データ共有が現在制限されているかどうかを示すブール値を返します。

シグネチャ

+ (BOOL)getLimitDataSharing;

使用例

Swift Objective-C
// Check if data sharing is limited
let isLimited = Singular.getLimitDataSharing()
if isLimited {
    print("Data sharing is currently limited")
}

handlePushNotification

Singular.handlePushNotification メソッド

アトリビューション用のプッシュ通知ペイロードを処理します。このメソッドは、アプリがプッシュ通知を受信したときにSingularが正しくアトリビューションできるように呼び出す必要があります。

シグネチャ

+ (BOOL)handlePushNotification:(NSDictionary *)pushNotificationPayload;

使用例

Swift Objective-C
// Handle a received push notification
func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    Singular.handlePushNotification(userInfo)
    completionHandler()
}

iapComplete

Singular.iapComplete メソッド

アプリ内購入完了イベントをトラッキングします。これらのメソッドは、アプリ内購入トランザクションが完了したときに呼び出す必要があります。

シグネチャ

+ (void)iapComplete:(id)transaction;

+ (void)iapComplete:(id)transaction
           withName:(NSString *)name;

+ (void)iapComplete:(id)transaction
     withAttributes:(id)value, ...;

+ (void)iapComplete:(id)transaction
           withName:(NSString *)name
     withAttributes:(id)value, ...;

使用例

Swift Objective-C
// Track IAP completion
Singular.iapComplete(transaction)

// Track IAP completion with custom name
Singular.iapComplete(transaction, withName: "premium_upgrade")

isAllTrackingStopped

Singular.isAllTrackingStopped メソッド

すべてのトラッキングが現在停止しているかどうかを確認します。このメソッドは、トラッキングが現在停止しているかどうかを示すブール値を返します。

シグネチャ

+ (BOOL)isAllTrackingStopped;

使用例

Swift Objective-C
// Check if tracking is stopped
if Singular.isAllTrackingStopped() {
    print("Tracking is currently stopped")
}

指定されたリンクホルダー(通常は NSURL または NSUserActivity)がSingular Linkを表すかどうかを返します。SingularがSDKの singularLinksHandlerを介してリンクを処理する場合、独自のディープリンク処理を短絡するためにこれを使用してください。

+ (BOOL)isSingularLink:(id)linkHolder;
Swift Objective-C
// Inspect an incoming URL before handling it yourself
func application(_ app: UIApplication,
                 open url: URL,
                 options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if Singular.isSingularLink(url) {
        // Singular's singularLinksHandler will receive the resolved link.
        return true
    }

    // Fall through to your own deep-link handling
    return handleCustomURL(url)
}

limitDataSharing

Singular.limitDataSharing メソッド

データ共有制限ステータスを設定します。ユーザーの同意またはプライバシー要件に基づいてデータ共有を制限するには、このメソッドを使用してください。

シグネチャ

+ (void)limitDataSharing:(BOOL)shouldLimitDataSharing;

使用例

Swift Objective-C
// To limit data sharing (e.g., when user opts out)
Singular.limitDataSharing(true)

// To enable full data sharing (e.g., when user opts in)
Singular.limitDataSharing(false)

registerDeviceTokenForUninstall

Singular.registerDeviceTokenForUninstall メソッド

アンインストールトラッキング用にデバイストークンを登録します。このメソッドは、アンインストールトラッキングを有効にするためにプッシュ通知トークンを使用して呼び出す必要があります。

シグネチャ

+ (void)registerDeviceTokenForUninstall:(NSData *)deviceToken;

使用例

Swift Objective-C
// Register device token for uninstall tracking
func application(_ application: UIApplication,
                 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Singular.registerDeviceTokenForUninstall(deviceToken)
}

resumeAllTracking

Singular.resumeAllTracking メソッド

以前に停止されたすべてのトラッキングアクティビティを再開します。トラッキングが停止された後に再有効化するには、このメソッドを使用してください。

シグネチャ

+ (void)resumeAllTracking;

使用例

Swift Objective-C
// Resume tracking when user opts back in
Singular.resumeAllTracking()

revenue

Singular.revenue メソッド

通貨、金額、商品詳細などのさまざまなパラメータを使用して収益イベントをトラッキングします。これにより、アプリケーションの包括的な収益トラッキングが可能になります。

シグネチャ

+ (void)revenue:(id)transaction;

+ (void)revenue:(id)transaction withAttributes:(NSDictionary *)attributes;

+ (void)revenue:(NSString *)currency amount:(double)amount;

+ (void)revenue:(NSString *)currency
         amount:(double)amount
   withAttributes:(NSDictionary *)attributes;

+ (void)revenue:(NSString *)currency
         amount:(double)amount
     productSKU:(NSString *)productSKU
    productName:(NSString *)productName
productCategory:(NSString *)productCategory
productQuantity:(int)productQuantity
   productPrice:(double)productPrice;

使用例

Swift Objective-C
// Track revenue with currency and amount
Singular.revenue("USD", amount: 9.99)

// Track revenue with additional attributes
Singular.revenue("USD", amount: 19.98, withAttributes: [
    "product_id": "premium_gems",
    "quantity": 2
])

// Track revenue with detailed product information
Singular.revenue("USD",
                 amount: 19.98,
                 productSKU: "SKU123456",
                 productName: "Premium Sword",
                 productCategory: "Weapons",
                 productQuantity: 2,
                 productPrice: 9.99)

// Track revenue from a StoreKit SKPaymentTransaction
// (typically inside SKPaymentTransactionObserver.paymentQueue(_:updatedTransactions:))
func paymentQueue(_ queue: SKPaymentQueue,
                  updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction in transactions where transaction.transactionState == .purchased {
        Singular.revenue(transaction)
        SKPaymentQueue.default().finishTransaction(transaction)
    }
}

setCustomUserId

Singular.setCustomUserId メソッド

現在のユーザーにカスタムユーザーIDを設定します。これにより、Singularデータを独自のユーザー識別システムに関連付けることができます。

シグネチャ

+ (void)setCustomUserId:(NSString *)customUserId;

使用例

Swift Objective-C
// Set custom user ID after user logs in
Singular.setCustomUserId("user_123456")

setDeviceCustomUserId

非推奨機能: 代わりにsetCustomUserIdを使用してください。

Singular.setDeviceCustomUserId メソッド

デバイスレベルでカスタムユーザーIDを設定します。これにより、Singularデータをデバイスレベルで独自のユーザー識別システムに関連付けることができます。

シグネチャ

+ (void)setDeviceCustomUserId:(NSString *)customUserId;

使用例

Swift Objective-C
// Set device-level custom user ID
Singular.setDeviceCustomUserId("device_user_123456")

setGlobalProperty

Singular.setGlobalProperty メソッド

すべてのイベントとともに送信されるグローバルプロパティを設定します。これにより、毎回指定することなく、すべてのイベントに一貫した属性を追加できます。

シグネチャ

+ (BOOL)setGlobalProperty:(NSString *)key
                 andValue:(NSString *)value
         overrideExisting:(BOOL)overrideExisting;

使用例

Swift Objective-C
// Set a global property
let success = Singular.setGlobalProperty("user_tier",
                                         andValue: "premium",
                                         overrideExisting: true)
if success {
    print("Global property set successfully")
}

setLimitAdvertisingIdentifiers

Singular.setLimitAdvertisingIdentifiers メソッド

広告識別子収集のランタイム制限を有効または無効にします。これは設定時のプロパティ SingularConfig.limitAdvertisingIdentifiersのランタイム同等版であり、 Singular.start(_:)の後の任意の時点で切り替え可能です。

このメソッドはSingular Kids SDKビルドではコンパイルから除外されます( #ifndef SINGULAR_KIDSでガードされます)。 Singular-Kids-SDKを統合している場合、このメソッドは利用できません。Kids SDKはより厳格な識別子処理を自動的に適用します。

シグネチャ

+ (void)setLimitAdvertisingIdentifiers:(BOOL)enabled;

使用例

Swift Objective-C
// Limit advertising identifiers at runtime (e.g., after a consent dialog)
Singular.setLimitAdvertisingIdentifiers(true)

setLoggingEnabled

Singular.setLoggingEnabled メソッド

ランタイムにSDKログを切り替えます。 SingularConfig.enableLoggingのランタイム対応版です。これが YESに設定され、かつ setLogLevel:SingularLogLevelNoneより上に設定されるまで、ログは出力されません。

シグネチャ

+ (void)setLoggingEnabled:(BOOL)enabled;

使用例

Swift Objective-C
// Enable SDK logging for debug builds
#if DEBUG
Singular.setLoggingEnabled(true)
Singular.setLogLevel(.debug)
#endif

setLogLevel

Singular.setLogLevel メソッド

ランタイムにSDKログの詳細度を設定します。 SingularConfig.logLevelのランタイム対応版です。利用可能なレベルは SingularLogLevel.hで定義されています: SingularLogLevelNone, SingularLogLevelError, SingularLogLevelWarning, SingularLogLevelInfo, SingularLogLevelDebug, SingularLogLevelVerbose

シグネチャ

+ (void)setLogLevel:(SingularLogLevel)logLevel;

使用例

Swift Objective-C
// Set verbose logging for detailed debugging
Singular.setLoggingEnabled(true)
Singular.setLogLevel(.verbose)

setSessionTimeout

Singular.setSessionTimeout メソッド

セッションタイムアウトを秒単位で設定します。これは、アプリがバックグラウンドに移行した後、ユーザーセッションがどれだけ続くかを決定します。

シグネチャ

+ (void)setSessionTimeout:(int)timeout;

使用例

Swift Objective-C
// Set session timeout to 2 minutes
Singular.setSessionTimeout(120)

skanGetConversionValue

Singular.skanGetConversionValue メソッド

現在のSKAdNetworkコンバージョン値を取得します。このメソッドは、SKAdNetworkアトリビューションに使用される現在のコンバージョン値を返します。

シグネチャ

+ (NSNumber *)skanGetConversionValue;

使用例

Swift Objective-C
// Get the current SKAdNetwork conversion value
let conversionValue = Singular.skanGetConversionValue()
print("Current conversion value: \(conversionValue ?? 0)")

skanRegisterAppForAdNetworkAttribution

Singular.skanRegisterAppForAdNetworkAttribution メソッド

SKAdNetworkアトリビューション用にアプリを登録します。iOSでSKAdNetworkアトリビューションを有効にするには、このメソッドを呼び出す必要があります。

シグネチャ

+ (void)skanRegisterAppForAdNetworkAttribution;

使用例

Swift Objective-C
// Register for SKAdNetwork attribution
Singular.skanRegisterAppForAdNetworkAttribution()

skanUpdateConversionValue

Singular.skanUpdateConversionValue メソッド

SKAdNetworkコンバージョン値を更新します。これらのメソッドを使用すると、SKAdNetworkアトリビューションに使用されるコンバージョン値を手動で更新できます。

シグネチャ

+ (BOOL)skanUpdateConversionValue:(NSInteger)conversionValue;

+ (void)skanUpdateConversionValue:(NSInteger)conversionValue
                           coarse:(NSInteger)coarse
                             lock:(BOOL)lock;

使用例

Swift Objective-C
// Update the SKAdNetwork conversion value
let success = Singular.skanUpdateConversionValue(5)
if success {
    print("Conversion value updated successfully")
}

// Update SKAdNetwork 4.0 conversion values (iOS 16.1+)
Singular.skanUpdateConversionValue(5,   // fine value (0-63)
                                   coarse: 1,   // coarse value (0=low, 1=medium, 2=high)
                                   lock: false)

start

Singular.start メソッド

指定された設定でSingular SDKを初期化します。これは、Singular SDKの使用を開始するために最初に呼び出すべきメソッドです。

シグネチャ

+ (BOOL)start:(SingularConfig *)config;

使用例

Swift Objective-C
// Create configuration object
let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET")

// Configure additional options if needed
config.customUserId = "user-123456"
config.sessionTimeout = 60

// Initialize the SDK
Singular.start(config)

startSession

Singular.startSession メソッド

Singular SDKで新しいセッションを開始します。起動オプション、ユーザーアクティビティ、ディープリンク処理など、さまざまな初期化シナリオに対応する複数のバリアントが利用できます。

シグネチャ

+ (void)startSession:(NSString *)apiKey withKey:(NSString *)apiSecret;

+ (BOOL)startSession:(NSString *)apiKey
             withKey:(NSString *)apiSecret
    andLaunchOptions:(NSDictionary *)launchOptions
withSingularLinkHandler:(void (^)(SingularLinkParams *))handler;

+ (BOOL)startSession:(NSString *)apiKey
             withKey:(NSString *)apiSecret
    andLaunchOptions:(NSDictionary *)launchOptions
withSingularLinkHandler:(void (^)(SingularLinkParams *))handler
andShortLinkResolveTimeout:(long)timeoutSec;

+ (void)startSession:(NSString *)apiKey
             withKey:(NSString *)apiSecret
    andLaunchOptions:(NSDictionary *)launchOptions;

使用例

Swift Objective-C
// Simple session start
Singular.startSession("API_KEY", withKey: "API_SECRET")

// Session start with deep link handler
Singular.startSession("API_KEY",
                      withKey: "API_SECRET",
                      andLaunchOptions: launchOptions,
                      withSingularLinkHandler: { params in
    if let deeplink = params.deeplink {
        print("Deep link received: \(deeplink)")
    }
})

stopAllTracking

Singular.stopAllTracking メソッド

すべてのトラッキングアクティビティを停止します。ユーザーがオプトアウトする場合やプライバシー対応のためにトラッキングを無効にするには、このメソッドを使用してください。

シグネチャ

+ (void)stopAllTracking;

使用例

Swift Objective-C
// Stop tracking when user opts out
Singular.stopAllTracking()

trackingOptIn

Singular.trackingOptIn メソッド

ユーザーがトラッキングにオプトインしたことを示します。ユーザーがトラッキングおよびデータ収集に明示的に同意する場合に、このメソッドを呼び出してください。

シグネチャ

+ (void)trackingOptIn;

使用例

Swift Objective-C
// User has opted in to tracking
Singular.trackingOptIn()

trackingUnder13

Singular.trackingUnder13 メソッド

ユーザーが13歳未満であることを示します。13歳未満のユーザーに対するCOPPAおよびその他の規制に準拠するために、このメソッドを呼び出してください。

シグネチャ

+ (void)trackingUnder13;

使用例

Swift Objective-C
// Notify Singular the user is under 13 years old
Singular.trackingUnder13()

unsetCustomUserId

Singular.unsetCustomUserId メソッド

以前に設定されたカスタムユーザーIDを削除します。ユーザーがログアウトする場合、または現在のユーザーIDとイベントを関連付けたくなくなった場合に、このメソッドを呼び出してください。

シグネチャ

+ (void)unsetCustomUserId;

使用例

Swift Objective-C
// Clear custom user ID when user logs out
Singular.unsetCustomUserId()

unsetGlobalProperty

Singular.unsetGlobalProperty メソッド

以前に設定されたグローバルプロパティを削除します。特定のグローバルプロパティをイベントと一緒に送信したくなくなった場合に、このメソッドを呼び出してください。

シグネチャ

+ (void)unsetGlobalProperty:(NSString *)key;

使用例

Swift Objective-C
// Remove a global property
Singular.unsetGlobalProperty("user_tier")