React Native SDKメソッドリファレンス
この包括的なリファレンスは、モバイルアプリのトラッキングのためのSingular SDKで利用可能なすべてのメソッドを文書化したものです。SDKは初期化、ユーザー識別、イベントトラッキング、収益レポート、アトリビューション、データプライバシーコンプライアンス、コンフィギュレーションなどの機能を提供します。各メソッドには説明、署名、実用的な使用例が記載されており、開発者がSingular SDKの機能をアプリケーションに統合するのに役立ちます。
adRevenue
Singular.adRevenue Method
詳細な広告データ情報で広告収益イベントを追跡します。
シグネチャ
static adRevenue(adData: SingularAdData): void
使用例
// Create ad data object
const adData = new SingularAdData()
.withAdPlatform("AdMob")
.withAdType("Rewarded")
.withAdNetworkName("Google")
.withCurrency("USD")
.withRevenue(0.05);
// Track ad revenue event
Singular.adRevenue(adData);
clearGlobalProperties
Singular.clearGlobalProperties Method
以前に設定したすべてのグローバルプロパティを削除します。
シグネチャ
static clearGlobalProperties(): void
使用例
// Clear all global properties, for example when a user logs out
Singular.clearGlobalProperties();
createReferrerShortLink
Singular.createReferrerShortLink Method
共有やアトリビューションに使用できる、リファラー情報付きのショートリンクを作成します。
署名
static createReferrerShortLink(baseLink: string, referrerName: string, referrerId: string, passthroughParams: SerializableObject, completionHandler: (result: string, error: string) => void): void
使用例
Singular.createReferrerShortLink(
"https://sample.sng.link/B4tbm/v8fp?_dl=https%3A%2F%2Fabc.com",
"John Doe", // Referrer Name
"aq239897", // Referrer ID
{ "channel": "sms", "campaign": "summer_promo" }, // Passthrough parameters
(shortLinkURL, error) => { if (error) {
console.error("Error creating short link:", error); return; }
console.log("Generated short link:", shortLinkURL);
// Share the link with users
}
);
customRevenue
Singular.customRevenue Method
指定したイベント名、通貨、金額でカスタム収益イベントを追跡します。
- カスタム収益イベント名は32 ASCII文字に制限されています。ASCII文字以外の場合、UTF-8に変換すると32バイトに制限されます。
-
通貨コードはすべて大文字で、3文字のISO 4217通貨コードに準拠する必要があります。
署名
static customRevenue(eventName: string, currency: string, amount: number): void
使用例
// Track a custom revenue event
Singular.customRevenue("premium_subscription", "USD", 9.99);
customRevenueWithArgs
Singular.customRevenueWithArgs Method
指定されたイベント名、通貨、金額、および追加のカスタム属性を持つカスタム収益イベントを追跡します。
- カスタム収益イベント名は、32 ASCII 文字に制限されています。非 ASCII 文字の場合、UTF-8 に変換すると 32 バイトに制限されます。
- イベント属性名と属性値は500 ASCII文字に制限されます。
-
通貨コードはすべて大文字で、3文字のISO 4217通貨コードに準拠する必要があります。
署名
static customRevenueWithArgs(eventName: string, currency: string, amount: number, args: SerializableObject): void
使用例
// Track a custom revenue event with additional parameters
Singular.customRevenueWithArgs(
"in_app_purchase",
"USD",
5.99,
{
"product_id": "com.app.gems_pack_small",
"quantity": 1,
"transaction_id": "T12345678",
"receipt_id": "R98765432"
}
);
event
Singular.event Method
SingularのSDKを使ってシンプルなカスタムイベントをトラッキングします。
- イベント名は32 ASCII文字までです。非ASCII文字の場合、UTF-8に変換すると32バイトになります。
シグネチャ
static event(eventName: string): void
使用例
// Track a simple event
Singular.event("level_completed");
eventWithArgs
Singular.eventWithArgs Method
Singular's SDKで追加属性を持つカスタムイベントをトラッキングします。
- イベント名は32 ASCII文字に制限されています。非ASCII文字の場合、UTF-8に変換すると32バイトになります。
- イベント属性名と属性値は500 ASCII文字に制限されています。
シグネチャ
static eventWithArgs(eventName: string, args: SerializableObject): void
使用例
// Track an event with additional parameters
Singular.eventWithArgs(
"level_completed",
{
"level_number": 5,
"difficulty": "hard",
"time_spent": 120,
"score": 9500
}
);
getLimitDataSharing
Singular.getLimitDataSharing Method
ユーザーの現在のデータ共有制限ステータスを取得します。
署名
static getLimitDataSharing(): boolean
使用例
// Check if data sharing is limited
const isLimited = Singular.getLimitDataSharing();
console.log("Data sharing limitation status:", isLimited);
// Use the status to adjust app behavior
if (isLimited) {
// Adjust functionality for users with limited data sharing
}
getGlobalProperties
Singular.getGlobalProperties Method
現在設定されているすべてのグローバル・プロパティを取得します。
署名
static getGlobalProperties(): Map<string, string>
使用例
// Get all global properties
const properties = Singular.getGlobalProperties();
// Iterate through properties
properties.forEach((value, key) => {
console.log(${key}: ${value});
});
inAppPurchase
Singular.inAppPurchase Method
このメソッドでは、アプリ内のトランザクションを管理するためにReact Nativeのアプリ内課金パッケージを使用する必要があります。
購入の詳細を含むアプリ内購入イベントを追跡します。
- イベント名は32 ASCII文字に制限されています。ASCII文字以外の場合、UTF-8に変換すると32バイトになります。
署名
static inAppPurchase(eventName: string, purchase: SingularPurchase): void
使用例
// Add the Singular Purchase Class imports
import {
Singular,
SingularConfig,
Events,
SingularPurchase,
SingularIOSPurchase,
SingularAndroidPurchase } from 'singular-react-native';
// Create purchase object
let singularPurchase = null;
if (Platform.OS === 'ios') {
singularPurchase = new SingularIOSPurchase(
product.revenue,
product.currency,
purchase.productId,
purchase.transactionId,
purchase.transactionReceipt,
);
} else if (Platform.OS === 'android'){
singularPurchase = new SingularAndroidPurchase(
product.revenue,
product.currency,
purchase.transactionReceipt,
purchase.signatureAndroid,
);
}
// Track in-app purchase
Singular.inAppPurchase('iap_purchase', singularPurchase);
inAppPurchaseWithArgs
Singular.inAppPurchaseWithArgs Method
このメソッドでは、アプリ内のトランザクションを管理するためにReact Nativeのアプリ内課金パッケージを使用する必要があります。
購入の詳細と追加のカスタム属性を持つアプリ内購入イベントを追跡します。
- イベント名は32 ASCII文字に制限されています。非ASCII文字の場合、UTF-8に変換すると32バイトに制限されます。
- イベント属性名と属性値は500 ASCII文字に制限されます。
シグネチャ
static inAppPurchaseWithArgs(eventName: string, purchase: SingularPurchase, args: SerializableObject): void
使用例
// Add the Singular Purchase Class imports
import {
Singular,
SingularConfig,
Events,
SingularPurchase,
SingularIOSPurchase,
SingularAndroidPurchase } from 'singular-react-native';
// Create purchase object
let singularPurchase = null;
if (Platform.OS === 'ios') {
singularPurchase = new SingularIOSPurchase(
product.revenue,
product.currency,
purchase.productId,
purchase.transactionId,
purchase.transactionReceipt,
);
} else if (Platform.OS === 'android'){
singularPurchase = new SingularAndroidPurchase(
product.revenue,
product.currency,
purchase.transactionReceipt,
purchase.signatureAndroid,
);
}
// Track in-app purchase with additional attributes
Singular.inAppPurchaseWithArgs(
"iap_purchase",
singularPurchase,
{
"is_first_purchase": true,
"subscription_type": "yearly",
"discount_applied": "holiday_special",
"previous_subscription": "monthly"
}
);
init
Singular.init Method
提供された設定でSingular SDKを初期化します。config パラメータはSingularConfig オブジェクトで、コンストラクタnew SingularConfig(apikey: string, secret: string) を使用して有効なSDK Key (apiKey) とSecret (secret) をインスタンス化する必要があります。
署名
static init(config: SingularConfig): void
使用例
// Create configuration
const config = new SingularConfig('SDK KEY', 'SDK SECRET')
.withCustomUserId("user123")
.withSessionTimeoutInSec(60)
.withLimitDataSharing(false)
.withSingularLink((params) => {
// Handle deep link parameters
console.log("Deep link received:", params);
});
// Initialize Singular SDK
Singular.init(config);
isAllTrackingStopped
Singular.isAllTrackingStopped Method
SDK ですべてのトラッキングが停止されているかどうかをチェックします。
シグネチャ
static isAllTrackingStopped(): boolean
使用例
// Check if tracking is currently stopped
const isTrackingStopped = Singular.isAllTrackingStopped();
// Adjust UI based on tracking status
if (isTrackingStopped) {
console.log("All tracking is currently stopped");
// Update UI to reflect tracking status
} else {
console.log("Tracking is active");
}
limitDataSharing
Singular.limitDataSharing Method
現在のユーザーのデータ共有を制限します。
署名
static limitDataSharing(shouldLimitDataSharing: boolean): void
使用例
// 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);
resumeAllTracking
Singular.resumeAllTracking Method
すべてのトラッキングを再開します。
署名
static resumeAllTracking(): void
使用例
// Resume tracking when user opts back in
Singular.resumeAllTracking();
console.log("Tracking has been resumed");
// Update UI to reflect that tracking is now active
revenue
Singular.revenue Method
通貨と金額を指定して、単純な収益イベントをトラッキングします。
-
通貨コードはすべて大文字で、3文字のISO 4217通貨コードに準拠する必要があります。
署名
static revenue(currency: string, amount: number): void
使用例
// Track a simple revenue event
Singular.revenue("USD", 19.99);
revenueWithArgs
Singular.revenueWithArgs Method
指定された通貨、金額、および追加のカスタム属性を持つ収益イベントを追跡します。
- イベント属性名と属性値は500 ASCII文字に制限されています。
-
通貨コードはすべて大文字で、3文字のISO 4217通貨コードに準拠する必要があります。
署名
static revenueWithArgs(currency: string, amount: number, args: SerializableObject): void
使用例
// Track a revenue event with additional parameters
Singular.revenueWithArgs(
"EUR",
9.99,
{
"subscription_type": "monthly",
"is_promotional": false,
"user_tier": "premium",
"payment_method": "credit_card"
}
);
setCustomUserId
Singular.setCustomUserId Method
SingularのSDKで使用する、現在のユーザーのカスタムユーザーIDを設定します。
署名
static setCustomUserId(customUserId: string): void
使用例
// Set the custom user ID after user logs in
Singular.setCustomUserId("user_123456");
setDeviceCustomUserId
Singular.setDeviceCustomUserId Method
エンタープライズ機能:クロスプラットフォームトラッキングのために、現在のデバイスにカスタムユーザーIDを関連付けます。
署名
static setDeviceCustomUserId(customUserId: string): void
使用例
// Set a device-level custom user ID
Singular.setDeviceCustomUserId("device_user_987654");
setGlobalProperty
Singular.setGlobalProperty Method
すべての後続イベントで送信されるグローバルプロパティを設定します。
シグネチャ
static setGlobalProperty(key: string, value: string, overrideExisting: boolean): boolean
使用例
// Set a global property that will be included with all events
const wasSet = Singular.setGlobalProperty("user_tier", "premium", true);
// Set another global property without overriding if it exists
Singular.setGlobalProperty("app_version", "2.1.3", false);
if (wasSet) {
console.log("Global property was set successfully");
}
setUninstallToken
Singular.setUninstallToken Method
プッシュ通知によるアンインストール追跡のためのデバイストークンを設定します。
シグネチャ
static setUninstallToken(token: string): void
使用例
// Set the device token for uninstall tracking
// This is typically obtained from the platform's push notification service
const deviceToken = "a1b2c3d4e5f6g7h8i9j0..."; // FCM or APNS token
Singular.setUninstallToken(deviceToken);
skanGetConversionValue
Singular.skanGetConversionValue Method
現在のSKAdNetworkの変換値を取得します(iOSのみ)。
署名
static skanGetConversionValue(): number | null
使用例
// Get the current SKAdNetwork conversion value
const conversionValue = Singular.skanGetConversionValue();
if (conversionValue !== null) {
console.log("Current conversion value:", conversionValue);
} else {
console.log("Conversion value not available");
}
skanRegisterAppForAdNetworkAttribution
Singular.skanRegisterAppForAdNetworkAttribution Method
SKAdNetworkアトリビューションにアプリを登録(iOSのみ)。
署名
static skanRegisterAppForAdNetworkAttribution(): void
使用例
// Register app for SKAdNetwork attribution
// This is typically called early in the app lifecycle
Singular.skanRegisterAppForAdNetworkAttribution();
skanUpdateConversionValue
Singular.skanUpdateConversionValue Method
SKAdNetworkの変換値を更新する(iOSのみ)。
署名
static skanUpdateConversionValue(conversionValue: number): boolean
使用例
// Update the SKAdNetwork conversion value
// Value must be between 0-63
const wasUpdated = Singular.skanUpdateConversionValue(12);
if (wasUpdated) {
console.log("Conversion value was updated successfully");
} else {
console.log("Failed to update conversion value");
}
skanUpdateConversionValues
Singular.skanUpdateConversionValues Method
SKAdNetwork4.0の変換値(fine、coarse、lock windowを含む)を更新(iOS 16.1+のみ)。
署名
static skanUpdateConversionValues(conversionValue: number, coarse: number, lock: boolean): void
使用例
// Update SKAdNetwork 4.0 conversion values
// Fine value: 0-63
// Coarse value: 0-2 (Low, Medium, High)
// Lock: whether to lock the postback window
Singular.skanUpdateConversionValues(45, 2, false);
// Example with named constants for clarity
const FINE_VALUE = 45;
const COARSE_VALUE_HIGH = 2;
const LOCK_WINDOW = false;
Singular.skanUpdateConversionValues(FINE_VALUE, COARSE_VALUE_HIGH, LOCK_WINDOW);
stopAllTracking
Singular.stopAllTracking Method
SDKの全てのトラッキングを停止。
署名
static stopAllTracking(): void
使用例
// Stop all tracking when user opts out
Singular.stopAllTracking();
console.log("All tracking has been stopped");
// Update UI to reflect that tracking is now disabled
trackingOptIn
Singular.trackingOptIn Method
アナリティクスとアトリビューション目的のトラッキングにユーザーをオプトインします。
署名
static trackingOptIn(): void
使用例
// Call when user has consented to tracking
Singular.trackingOptIn();
console.log("User has opted into tracking");
trackingUnder13
Singular.trackingUnder13 Method
ユーザーを13歳未満としてマークし、COPPAに従ってデータ収集を制限します。
署名
static trackingUnder13(): void
使用例
// If user is determined to be under 13 years old
Singular.trackingUnder13();
console.log("User marked as under 13, GDPR_UNDER_13 flag applied");
unsetCustomUserId
Singular.unsetCustomUserId Method
以前に設定したカスタムユーザーIDをSingularトラッキングから削除します。
署名
static unsetCustomUserId(): void
使用例
// Remove the custom user ID when user logs out
Singular.unsetCustomUserId();
console.log("Custom user ID has been removed");
unsetGlobalProperty
Singular.unsetGlobalProperty Method
以前に設定されたグローバルプロパティを削除します。
署名
static unsetGlobalProperty(key: string): void
使用例
// Remove a global property that is no longer needed
Singular.unsetGlobalProperty("temporary_campaign_id");
console.log("Global property has been removed");