### Initialize Singular SDK with Configuration (JavaScript) Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Initializes the Singular SDK using a configuration object. The `SingularConfig` class allows fluent configuration of deep linking, SKAdNetwork, session timeouts, privacy settings, and callbacks. Ensure you replace 'YOUR_API_KEY' and 'YOUR_SECRET' with your actual credentials. ```javascript import { Singular, SingularConfig } from 'singular-react-native'; // Basic initialization const config = new SingularConfig('YOUR_API_KEY', 'YOUR_SECRET'); // Full configuration with all options const fullConfig = new SingularConfig('YOUR_API_KEY', 'YOUR_SECRET') .withCustomUserId('user_12345') .withSessionTimeoutInSec(120) .withSkAdNetworkEnabled(true) .withManualSkanConversionManagement() .withWaitForTrackingAuthorizationWithTimeoutInterval(300) .withLimitDataSharing(false) .withLoggingEnabled() .withShortLinkResolveTimeout(15) .withGlobalProperty('app_version', '2.1.0', true) .withGlobalProperty('environment', 'production', true) .withFacebookAppId('YOUR_FACEBOOK_APP_ID') .withSingularLink((params) => { console.log('Deep link received:', params.deeplink); console.log('Passthrough data:', params.passthrough); console.log('Is deferred:', params.isDeferred); // Handle navigation based on deep link }) .withConversionValueUpdatedHandler((value) => { console.log('SKAN conversion value updated:', value); }) .withDeviceAttributionCallbackHandler((attributes) => { console.log('Device attribution:', attributes); }); Singular.init(fullConfig); ``` -------------------------------- ### Referrer Short Links Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Create short links for user referral programs with custom passthrough data. Track referral attribution and reward both referrers and referred users. ```APIDOC ## Referrer Short Links ### Description Create short links for user referral programs with custom passthrough data. Track referral attribution and reward both referrers and referred users. ### Method * `Singular.createReferrerShortLink(baseLink: string, referrerName: string, referrerId: string, passthroughParams: object, callback: function)`: * `baseLink` (string): The base URL for the short link. * `referrerName` (string): The name of the referrer. * `referrerId` (string): The ID of the referrer. * `passthroughParams` (object): Custom key-value pairs to pass through the link. * `callback` (function): A callback function that receives `(shortLink, error)`. ``` -------------------------------- ### Create Referrer Short Links (JavaScript) Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Generate short links for referral programs, allowing custom passthrough data. This enables tracking referral attribution and rewarding users. The callback function receives the generated short link or an error. ```javascript import { Singular } from 'singular-react-native'; // Create a referrer short link const baseLink = 'https://myapp.sng.link/abc123/referral'; const referrerName = 'John Doe'; const referrerId = 'user_john_123'; const passthroughParams = { campaign: 'summer_referral', reward_type: 'premium_week', source: 'in_app_share' }; Singular.createReferrerShortLink( baseLink, referrerName, referrerId, passthroughParams, (shortLink, error) => { if (error) { console.error('Failed to create short link:', error); return; } console.log('Share this link:', shortLink); // Output: https://myapp.sng.link/abc123/referral?_dl=... // Share via native share sheet or copy to clipboard } ); ``` -------------------------------- ### Track Ad Monetization Revenue with Singular React Native SDK Source: https://context7.com/singular-labs/react-native-sdk/llms.txt This code snippet shows how to track ad revenue using the Singular SDK. It covers basic ad revenue tracking and detailed tracking with extensive metadata, enabling accurate ROAS calculations. The `SingularAdData` class is used to structure the ad information. ```javascript import { Singular, SingularAdData } from 'singular-react-native'; // Basic ad revenue tracking const adData = new SingularAdData('AdMob', 'USD', 0.0025); Singular.adRevenue(adData); // Detailed ad revenue with all metadata const detailedAdData = new SingularAdData('ironSource', 'USD', 0.0150) .withNetworkName('Unity Ads') .withAdType('rewarded_video') .withGroupType('interstitial') .withAdPlacementName('level_complete_reward') .withAdUnitId('ca-app-pub-1234567890/9876543210') .withAdUnitName('Rewarded Video - Main') .withAdGroupId('group_123') .withAdGroupName('High Value Users') .withAdGroupPriority('high') .withImpressionId('imp_abc123xyz') .withPlacementId('placement_456') .withPrecision('estimated'); Singular.adRevenue(detailedAdData); // Track banner ad impression const bannerAdData = new SingularAdData('AppLovin', 'USD', 0.0008) .withAdType('banner') .withAdPlacementName('home_screen_banner') .withPrecision('exact'); Singular.adRevenue(bannerAdData); ``` -------------------------------- ### Use Predefined Events and Attributes in React Native SDK Source: https://context7.com/singular-labs/react-native-sdk/llms.txt This snippet demonstrates how to import and use predefined event constants and attributes from the 'singular-react-native' SDK. These constants ensure standardized tracking for user engagement, onboarding, commerce, subscriptions, gaming, and app lifecycle events. They are essential for leveraging Singular's reporting and optimization features. ```javascript import { Events, Attributes } from 'singular-react-native'; // Available predefined events const allEvents = { // User engagement sngLogin: Events.sngLogin, // 'sng_login' sngRate: Events.sngRate, // 'sng_rate' sngShare: Events.sngShare, // 'sng_share' sngInvite: Events.sngInvite, // 'sng_invite' sngSearch: Events.sngSearch, // 'sng_search', // Onboarding sngTutorialComplete: Events.sngTutorialComplete, // 'sng_tutorial_complete' sngCompleteRegistration: Events.sngCompleteRegistration, // 'sng_complete_registration', // Commerce sngContentView: Events.sngContentView, // 'sng_content_view' sngContentViewList: Events.sngContentViewList, // 'sng_content_view_list' sngAddToCart: Events.sngAddToCart, // 'sng_add_to_cart' sngAddToWishlist: Events.sngAddToWishlist, // 'sng_add_to_wishlist' sngViewCart: Events.sngViewCart, // 'sng_view_cart' sngCheckoutInitiated: Events.sngCheckoutInitiated, // 'sng_checkout_initiated' sngAddPaymentInfo: Events.sngAddPaymentInfo, // 'sng_add_payment_info' sngEcommercePurchase: Events.sngEcommercePurchase, // 'sng_ecommerce_purchase', // Subscriptions sngStartTrial: Events.sngStartTrial, // 'sng_start_trial' sngSubscribe: Events.sngSubscribe, // 'sng_subscribe', // Gaming sngLevelAchieved: Events.sngLevelAchieved, // 'sng_level_achieved' sngAchievementUnlocked: Events.sngAchievementUnlocked, // 'sng_achievement_unlocked' sngSpentCredits: Events.sngSpentCredits, // 'sng_spent_credits', // Travel/Booking sngBook: Events.sngBook, // 'sng_book', // App lifecycle sngUpdate: Events.sngUpdate, // 'sng_update' sngSubmitApplication: Events.sngSubmitApplication // 'sng_submit_application' }; // Available predefined attributes const allAttributes = { // Content sngAttrContentId: Attributes.sngAttrContentId, // 'sng_attr_content_id' sngAttrContentType: Attributes.sngAttrContentType, // 'sng_attr_content_type' sngAttrContent: Attributes.sngAttrContent, // 'sng_attr_content' sngAttrContentList: Attributes.sngAttrContentList, // 'sng_attr_content_list', // Transaction sngAttrTransactionId: Attributes.sngAttrTransactionId, // 'sng_attr_transaction_id' sngAttrItemPrice: Attributes.sngAttrItemPrice, // 'sng_attr_item_price' sngAttrQuantity: Attributes.sngAttrQuantity, // 'sng_attr_quantity' sngAttrCouponCode: Attributes.sngAttrCouponCode, // 'sng_attr_coupon_code', // User sngAttrRegistrationMethod: Attributes.sngAttrRegistrationMethod, // 'sng_attr_registration_method' sngAttrSubscriptionId: Attributes.sngAttrSubscriptionId, // 'sng_attr_subscription_id', // Gaming sngAttrLevel: Attributes.sngAttrLevel, // 'sng_attr_level' sngAttrScore: Attributes.sngAttrScore, // 'sng_attr_score' sngAttrAchievementId: Attributes.sngAttrAchievementId, // 'sng_attr_achievement_id', // Search sngAttrSearchString: Attributes.sngAttrSearchString, // 'sng_attr_search_string', // Location sngAttrLatitude: Attributes.sngAttrLatitude, // 'sng_attr_latitude' sngAttrLongitude: Attributes.sngAttrLongitude, // 'sng_attr_longitude' sngAttrLocation: Attributes.sngAttrLocation, // 'sng_attr_location', // Status sngAttrSuccess: Attributes.sngAttrSuccess, // 'sng_attr_success' sngAttrValid: Attributes.sngAttrValid, // 'sng_attr_valid' sngAttrRating: Attributes.sngAttrRating // 'sng_attr_rating' }; ``` -------------------------------- ### Track Revenue Events with Singular React Native SDK Source: https://context7.com/singular-labs/react-native-sdk/llms.txt This snippet demonstrates how to track various revenue events, including simple revenue, revenue with additional attributes, custom revenue events, and in-app purchases for both iOS and Android. It utilizes the Singular SDK to send this data for analysis. ```javascript import { Singular, SingularPurchase, SingularIOSPurchase, SingularAndroidPurchase } from 'singular-react-native'; // Simple revenue tracking Singular.revenue('USD', 9.99); // Revenue with additional attributes Singular.revenueWithArgs('USD', 49.99, { product_name: 'Premium Subscription', subscription_period: 'monthly', discount_applied: false }); // Custom revenue event with name Singular.customRevenue('premium_upgrade', 'USD', 99.99); // Custom revenue with attributes Singular.customRevenueWithArgs('subscription_renewal', 'EUR', 12.99, { subscription_tier: 'gold', renewal_count: 3, auto_renewed: true }); // iOS in-app purchase with receipt validation const iosPurchase = new SingularIOSPurchase( 4.99, // revenue 'USD', // currency 'com.app.premium_item', // productId 'TXN_123456789', // transactionId 'BASE64_RECEIPT_DATA' // receipt ); Singular.inAppPurchase('item_purchased', iosPurchase); // Android in-app purchase with signature validation const androidPurchase = new SingularAndroidPurchase( 4.99, // revenue 'USD', // currency 'PURCHASE_RECEIPT_JSON', // receipt 'SIGNATURE_STRING' // signature ); Singular.inAppPurchase('item_purchased', androidPurchase); // In-app purchase with additional attributes Singular.inAppPurchaseWithArgs('subscription_started', iosPurchase, { plan_type: 'annual', trial_converted: true, promo_code: 'SAVE20' }); ``` -------------------------------- ### Set and Manage Global Properties with Singular React Native SDK Source: https://context7.com/singular-labs/react-native-sdk/llms.txt This code demonstrates how to set, retrieve, and clear global properties in the Singular React Native SDK. These properties are attached to all subsequent events and are useful for segmentation and A/B testing. ```javascript import { Singular } from 'singular-react-native'; // Set global properties (returns true if successful) const success = Singular.setGlobalProperty('user_tier', 'premium', true); Singular.setGlobalProperty('ab_test_group', 'variant_b', true); Singular.setGlobalProperty('app_language', 'en-US', false); // won't override if exists // Get all global properties const properties = Singular.getGlobalProperties(); console.log('Current properties:', properties); // Output: { user_tier: 'premium', ab_test_group: 'variant_b', app_language: 'en-US' } // Remove a specific property Singular.unsetGlobalProperty('ab_test_group'); // Clear all global properties Singular.clearGlobalProperties(); ``` -------------------------------- ### Privacy and Tracking Controls Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Manage user privacy preferences and tracking consent for GDPR, CCPA, and COPPA compliance. Control data sharing and tracking behavior based on user consent. ```APIDOC ## Privacy and Tracking Controls ### Description Manage user privacy preferences and tracking consent for GDPR, CCPA, and COPPA compliance. Control data sharing and tracking behavior based on user consent. ### Methods * `Singular.trackingOptIn()`: User opted into tracking. * `Singular.trackingUnder13()`: User is under 13 (COPPA compliance). * `Singular.stopAllTracking()`: Completely stop all tracking. * `Singular.resumeAllTracking()`: Resume tracking after user consent. * `Singular.isAllTrackingStopped()`: Check if tracking is stopped. Returns a boolean. * `Singular.limitDataSharing(boolean)`: Limit data sharing (CCPA compliance). Pass `true` to limit, `false` to not limit. * `Singular.getLimitDataSharing()`: Check data sharing status. Returns a boolean. * `Singular.setLimitAdvertisingIdentifiers(boolean)`: Limit advertising identifiers collection. Pass `true` to limit, `false` to not limit. ``` -------------------------------- ### Manage Privacy and Tracking Controls (JavaScript) Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Control user privacy and tracking consent for GDPR, CCPA, and COPPA compliance. This includes opting in/out of tracking, handling under-13 users, limiting data sharing, and managing advertising identifier collection. ```javascript import { Singular } from 'singular-react-native'; // User opted into tracking Singular.trackingOptIn(); // User is under 13 (COPPA compliance) Singular.trackingUnder13(); // Completely stop all tracking Singular.stopAllTracking(); // Resume tracking after user consent Singular.resumeAllTracking(); // Check if tracking is stopped const isStopped = Singular.isAllTrackingStopped(); console.log('Tracking stopped:', isStopped); // Limit data sharing (CCPA compliance) Singular.limitDataSharing(true); // Check data sharing status const isLimited = Singular.getLimitDataSharing(); console.log('Data sharing limited:', isLimited); // Limit advertising identifiers collection Singular.setLimitAdvertisingIdentifiers(true); ``` -------------------------------- ### Manage User Identity with Singular React Native SDK Source: https://context7.com/singular-labs/react-native-sdk/llms.txt This snippet demonstrates how to manage user identifiers for cross-device attribution and analytics using the Singular SDK. It includes setting custom user IDs, device-level custom user IDs, and clearing them upon user logout. ```javascript import { Singular } from 'singular-react-native'; // Set custom user ID after login Singular.setCustomUserId('user_abc123'); // Set device-level custom user ID (persists across sessions) Singular.setDeviceCustomUserId('device_user_xyz789'); // Clear custom user ID on logout Singular.unsetCustomUserId(); ``` -------------------------------- ### Track Custom Events with Attributes (JavaScript) Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Tracks user actions and in-app events using predefined or custom event names, optionally with associated attributes. This allows for detailed analytics on user behavior. Predefined events and attributes from `Events` and `Attributes` are recommended for consistency. ```javascript import { Singular, Events, Attributes } from 'singular-react-native'; // Simple event tracking Singular.event('button_clicked'); Singular.event(Events.sngLogin); Singular.event(Events.sngTutorialComplete); // Event with custom attributes Singular.eventWithArgs(Events.sngCompleteRegistration, { [Attributes.sngAttrRegistrationMethod]: 'email', [Attributes.sngAttrSuccess]: 'true', signup_source: 'onboarding_flow' }); // Track content view with details Singular.eventWithArgs(Events.sngContentView, { [Attributes.sngAttrContentId]: 'article_789', [Attributes.sngAttrContentType]: 'blog_post', category: 'technology', reading_time: 5 }); // Track search event Singular.eventWithArgs(Events.sngSearch, { [Attributes.sngAttrSearchString]: 'react native tutorial', results_count: 42 }); // Track level achievement in games Singular.eventWithArgs(Events.sngLevelAchieved, { [Attributes.sngAttrLevel]: '15', [Attributes.sngAttrScore]: '25000', time_spent_seconds: 180 }); ``` -------------------------------- ### Manage SKAdNetwork (SKAN) Support (JavaScript) Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Handle iOS SKAdNetwork conversion values for privacy-compliant attribution. Supports SKAN 3.0 (single conversion value) and SKAN 4.0 (fine and coarse values). Call registerAppForAdNetworkAttribution early in the app lifecycle. ```javascript import { Singular } from 'singular-react-native'; // Register for SKAdNetwork attribution (call early in app lifecycle) Singular.skanRegisterAppForAdNetworkAttribution(); // Update SKAN 3.0 conversion value (0-63) const updateSuccess = Singular.skanUpdateConversionValue(42); // Update SKAN 4.0 conversion values // Parameters: fineValue (0-63), coarseValue (0=low, 1=medium, 2=high), lock (boolean) Singular.skanUpdateConversionValues( 35, // fine conversion value 2, // coarse value: high false // don't lock the conversion window ); // Get current conversion value const currentValue = Singular.skanGetConversionValue(); console.log('Current SKAN value:', currentValue); // null on Android, number on iOS ``` -------------------------------- ### Push Notification Attribution Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Track push notification opens and attribute conversions to specific campaigns. Handle push notification payloads to enable deep link resolution. ```APIDOC ## Push Notification Attribution ### Description Track push notification opens and attribute conversions to specific campaigns. Handle push notification payloads to enable deep link resolution. ### Methods * `Singular.handlePushNotification(pushPayload: object)`: Handle push notification when the app opens from a notification (iOS only). `pushPayload` is the notification object, expected to contain `singular_link` and `campaign_id`. * `Singular.setUninstallToken(token: string)`: Set the FCM/APNs token for uninstall tracking. ``` -------------------------------- ### SKAdNetwork (SKAN) Support Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Manage iOS SKAdNetwork conversion values for privacy-compliant attribution. Supports both SKAN 3.0 (single conversion value) and SKAN 4.0 (fine + coarse values). ```APIDOC ## SKAdNetwork (SKAN) Support ### Description Manage iOS SKAdNetwork conversion values for privacy-compliant attribution. Supports both SKAN 3.0 (single conversion value) and SKAN 4.0 (fine + coarse values). ### Methods * `Singular.skanRegisterAppForAdNetworkAttribution()`: Register for SKAdNetwork attribution. Call early in the app lifecycle. * `Singular.skanUpdateConversionValue(number)`: Update SKAN 3.0 conversion value (0-63). Returns a boolean indicating success. * `Singular.skanUpdateConversionValues(fineValue: number, coarseValue: number, lock: boolean)`: Update SKAN 4.0 conversion values. `fineValue` (0-63), `coarseValue` (0=low, 1=medium, 2=high), `lock` (boolean). * `Singular.skanGetConversionValue()`: Get current conversion value. Returns `null` on Android, a number on iOS. ``` -------------------------------- ### Handle Push Notification Attribution (JavaScript) Source: https://context7.com/singular-labs/react-native-sdk/llms.txt Track push notification opens and attribute conversions to specific campaigns. This function handles push notification payloads for deep link resolution and allows setting the FCM/APNs token for uninstall tracking. ```javascript import { Singular } from 'singular-react-native'; // Handle push notification when app opens from notification (iOS only) const pushPayload = { aps: { alert: 'Check out our new features!', badge: 1 }, singular_link: 'https://myapp.sng.link/campaign123', campaign_id: 'push_summer_2024' }; Singular.handlePushNotification(pushPayload); // Set FCM/APNs token for uninstall tracking Singular.setUninstallToken('FCM_OR_APNS_DEVICE_TOKEN_STRING'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.