### Submit iOS Device Identifiers Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Submit IDFA and IDFV for iOS attribution. Call this after App Tracking Transparency permission is granted. IDFV can be submitted immediately after SDK start. ```csharp #if UNITY_IOS using Apphud.Unity.SDK; using UnityEngine; using UnityEngine.iOS; public class IOSIdentifiersManager : MonoBehaviour { void Start() { // Submit IDFV immediately after SDK start string idfv = Device.vendorIdentifier; ApphudSDK.SetDeviceIdentifiers(null, idfv); } public void OnTrackingPermissionGranted() { // After user grants ATT permission, submit both identifiers string idfa = Device.advertisingIdentifier; string idfv = Device.vendorIdentifier; ApphudSDK.SetDeviceIdentifiers(idfa, idfv); } public void SubmitPushToken(string pushToken) { ApphudSDK.SubmitPushNotificationsTokenString(pushToken, (bool success) => { Debug.Log($"Push token submitted: {success}"); }); } public void TrackPurchaseInObserverMode(string paywallId, string placementId) { // Call before making purchase with your own code in Observer Mode ApphudSDK.WillPurchaseProductFrom(paywallId, placementId); } } #endif ``` -------------------------------- ### Initialize Apphud SDK Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Initialize the Apphud SDK at app launch with your API key. Enable debug logs before initialization if needed. The callback provides user information. ```csharp using Apphud.Unity.SDK; using Apphud.Unity.Domain; using UnityEngine; public class ApphudInitializer : MonoBehaviour { private const string APPHUD_API_KEY = "app_your_api_key_here"; void Start() { // Enable debug logs before initialization (optional) ApphudSDK.EnableDebugLogs(); // Basic initialization ApphudSDK.Start(APPHUD_API_KEY, OnUserRegistered); } private void OnUserRegistered(ApphudUser user) { Debug.Log($ ``` -------------------------------- ### Purchase Product with Apphud SDK Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Initiates a purchase for a product. Handles store communication and receipt validation. Tracks paywall display events for A/B testing analytics. For Android subscriptions, provide the offer token. ```csharp using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class PurchaseManager : MonoBehaviour { private ApphudPaywall _currentPaywall; private ApphudProduct _selectedProduct; public void ShowPaywall(ApphudPaywall paywall) { _currentPaywall = paywall; // Required for A/B testing analytics ApphudSDK.PaywallShown(paywall); // Display your paywall UI here } public void ClosePaywall() { // Required for A/B testing analytics when user dismisses without purchase ApphudSDK.PaywallClosed(_currentPaywall); } public void PurchaseProduct(ApphudProduct product) { _selectedProduct = product; #if UNITY_ANDROID // For Android subscriptions, get offer token from SubscriptionOfferDetails string offerIdToken = null; if (product.SubscriptionOfferDetails != null && product.SubscriptionOfferDetails.Count > 0) { offerIdToken = product.SubscriptionOfferDetails[0].OfferToken; } ApphudSDK.Purchase( product, offerIdToken: offerIdToken, oldToken: null, // For subscription upgrades/downgrades replacementMode: null, // Replacement mode for subscription updates consumableInAppProduct: false, callback: OnPurchaseComplete ); #else ApphudSDK.Purchase(product, callback: OnPurchaseComplete); #endif } private void OnPurchaseComplete(ApphudPurchaseResult result) { if (result.Error != null) { Debug.LogError($"Purchase failed: {result.Error.Message}"); #if UNITY_ANDROID if (result.UserCanceled) { Debug.Log("User canceled the purchase"); } #endif return; } if (result.Subscription != null) { Debug.Log($"Subscription purchased: {result.Subscription.ProductId}"); Debug.Log($"Status: {result.Subscription.Status}"); Debug.Log($"Is Active: {result.Subscription.IsActive}"); Debug.Log($"Expires At: {result.Subscription.ExpiresAt}"); } else if (result.NonRenewingPurchase != null) { Debug.Log($"One-time purchase: {result.NonRenewingPurchase.ProductId}"); Debug.Log($"Is Active: {result.NonRenewingPurchase.IsActive}"); } // Grant premium access if (ApphudSDK.HasPremiumAccess()) { UnlockPremiumContent(); } } private void UnlockPremiumContent() { Debug.Log("Premium content unlocked!"); } } ``` -------------------------------- ### Check Premium Access and Subscription Details in Unity Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Use these methods to verify user access levels and iterate through subscription or non-renewing purchase data. Ensure the Apphud SDK is initialized before calling these methods. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class AccessManager : MonoBehaviour { public bool IsPremiumUser() { // Returns true if user has ANY active subscription OR non-renewing purchase return ApphudSDK.HasPremiumAccess(); } public bool HasActiveSubscription() { // Returns true only for active auto-renewable subscriptions return ApphudSDK.HasActiveSubscription(); } public bool HasLifetimePurchase(string productId) { // Check specific non-renewing (lifetime) purchase return ApphudSDK.IsNonRenewingPurchaseActive(productId); } public void CheckSubscriptionDetails() { List subscriptions = ApphudSDK.Subscriptions(); foreach (var subscription in subscriptions) { Debug.Log($"Product: {subscription.ProductId}"); Debug.Log($"Status: {subscription.Status}"); Debug.Log($"Is Active: {subscription.IsActive}"); Debug.Log($"Auto-Renew Enabled: {subscription.IsAutoRenewEnabled}"); Debug.Log($"In Retry Billing: {subscription.IsInRetryBilling}"); // Handle different subscription states switch (subscription.Status) { case ApphudSubscriptionStatus.TRIAL: Debug.Log("User is in free trial"); break; case ApphudSubscriptionStatus.INTRO: Debug.Log("User is in introductory offer period"); break; case ApphudSubscriptionStatus.REGULAR: Debug.Log("User has regular paid subscription"); break; case ApphudSubscriptionStatus.GRACE: Debug.Log("User is in grace period"); break; case ApphudSubscriptionStatus.EXPIRED: Debug.Log("Subscription has expired"); break; case ApphudSubscriptionStatus.REFUNDED: Debug.Log("Subscription was refunded"); break; } } } public void CheckNonRenewingPurchases() { List purchases = ApphudSDK.NonRenewingPurchases(); foreach (var purchase in purchases) { Debug.Log($"Product: {purchase.ProductId}"); Debug.Log($"Is Active: {purchase.IsActive}"); Debug.Log($"Purchased At: {purchase.PurchasedAt}"); Debug.Log($"Is Consumable: {purchase.IsConsumable}"); } } } ``` -------------------------------- ### Load Paywalls with Apphud SDK Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Fetches paywalls directly from Apphud Product Hub. Handles product details from stores and provides custom JSON configuration. Use this to display purchase options to your users. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class PaywallsManager : MonoBehaviour { private List _paywalls; public void LoadPaywalls() { ApphudSDK.PaywallsDidLoadCallback(OnPaywallsLoaded, maxAttempts: 3); } private void OnPaywallsLoaded(List paywalls, ApphudError error) { if (error != null) { Debug.LogError($"Error loading paywalls: {error.Message}"); } _paywalls = paywalls; foreach (var paywall in paywalls) { Debug.Log($"Paywall: {paywall.Identifier}"); Debug.Log($" Is Default: {paywall.Default}"); Debug.Log($" Placement: {paywall.PlacementIdentifier ?? "None"}"); // Access custom JSON configuration for UI customization if (paywall.Json != null) { foreach (var kvp in paywall.Json) { Debug.Log($" Config: {kvp.Key} = {kvp.Value}"); } } // List all products in this paywall foreach (var product in paywall.Products) { Debug.Log($" Product ID: {product.ProductId}"); #if UNITY_IOS if (product.SKProduct != null) { Debug.Log($" Price: {product.SKProduct.Price} {product.SKProduct.PriceLocale.CurrencyCode}"); Debug.Log($" Title: {product.SKProduct.LocalizedTitle}"); } #elif UNITY_ANDROID Debug.Log($" Title: {product.ProductTitle}"); Debug.Log($" Type: {product.ProductType}"); #endif } } } } ``` -------------------------------- ### Grant Promotional Subscription Access Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Use this to grant free promotional subscription access for testing or marketing. Specify the number of days for the trial or a large number for lifetime access. ```csharp using Apphud.Unity.SDK; public class PromotionalManager : MonoBehaviour { public void GrantFreeTrial(int days) { ApphudSDK.GrantPromotional(days, OnPromotionalGranted); } public void GrantLifetimeAccess() { // Pass a very large number for lifetime access ApphudSDK.GrantPromotional(36500, OnPromotionalGranted); // ~100 years } private void OnPromotionalGranted(bool success) { if (success) { Debug.Log("Promotional access granted successfully!"); // Verify premium access if (ApphudSDK.HasPremiumAccess()) { Debug.Log("User now has premium access"); } } else { Debug.LogError("Failed to grant promotional access"); } } } ``` -------------------------------- ### Restore Purchases in Unity Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Implement the restore purchases functionality to sync user purchases from the store and update their subscription status in Apphud. This requires a button click listener to initiate the process and a callback to handle the completion status. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; using UnityEngine; using UnityEngine.UI; public class RestoreManager : MonoBehaviour { public Button restoreButton; public Text statusText; void Start() { restoreButton.onClick.AddListener(OnRestoreButtonClicked); } private void OnRestoreButtonClicked() { statusText.text = "Restoring purchases..."; restoreButton.interactable = false; ApphudSDK.RestorePurchases(OnRestoreComplete); } private void OnRestoreComplete( List subscriptions, List nonRenewingPurchases, ApphudError error) { restoreButton.interactable = true; if (error != null) { statusText.text = $"Restore failed: {error.Message}"; Debug.LogError($"Restore error: {error.Message}"); return; } // Check restored subscriptions bool hasActivePurchase = false; foreach (var subscription in subscriptions) { Debug.Log($"Restored subscription: {subscription.ProductId}"); if (subscription.IsActive) { hasActivePurchase = true; Debug.Log($"Active subscription found: {subscription.ProductId}"); } } foreach (var purchase in nonRenewingPurchases) { Debug.Log($"Restored purchase: {purchase.ProductId}"); if (purchase.IsActive) { hasActivePurchase = true; Debug.Log($"Active purchase found: {purchase.ProductId}"); } } if (hasActivePurchase) { statusText.text = "Purchases restored successfully!"; // Grant premium access } else { statusText.text = "No active purchases found."; } } } ``` -------------------------------- ### Load Fallback Paywalls Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Loads fallback paywalls from a local JSON file when network requests fail. Configure fallback JSON in the Apphud dashboard and add it to your project resources. Call this method to initiate the loading process. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class FallbackManager : MonoBehaviour { public void LoadFallbackPaywalls() { ApphudSDK.LoadFallbackPaywalls(OnFallbackLoaded); } private void OnFallbackLoaded(List paywalls, ApphudError error) { if (error != null) { Debug.LogError($"Fallback load error: {error.Message}"); return; } Debug.Log($"Loaded {paywalls.Count} fallback paywalls"); foreach (var paywall in paywalls) { Debug.Log($"Fallback paywall: {paywall.Identifier}"); Debug.Log($"Products count: {paywall.Products.Count}"); } } public void InvalidateCacheBeforeStart() { // Call before SDK initialization to force fresh data ApphudSDK.InvalidatePaywallsCache(); ApphudSDK.Start("your_api_key", null); } } ``` -------------------------------- ### Set Adjust Attribution Data Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Submit attribution data from Adjust. The `adjustData` dictionary should contain the relevant data from Adjust. The `adjustAdid` is the Adjust Ad ID. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class AttributionManager : MonoBehaviour { public void SetAdjustAttribution(Dictionary adjustData, string adjustAdid) { var attributionData = new ApphudAttributionData(rawData: adjustData); ApphudSDK.SetAttribution( ApphudAttributionProvider.ADJUST, attributionData, identifier: adjustAdid ); } } ``` -------------------------------- ### Set Custom Attribution with Overrides Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Set custom attribution data, allowing overrides for specific fields like ad network, channel, campaign, ad set, creative, keyword, and custom parameters. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class AttributionManager : MonoBehaviour { public void SetCustomAttributionWithOverrides() { // Override specific attribution fields var attributionData = new ApphudAttributionData( rawData: new Dictionary(), adNetwork: "Meta Ads", channel: "Instagram Feed", campaign: "Summer_Sale_2024", adSet: "US_18_35", creative: "video_testimonial_v2", keyword: "fitness app", custom1: "influencer_promo", custom2: "discount_50" ); ApphudSDK.SetAttribution(ApphudAttributionProvider.CUSTOM, attributionData); } } ``` -------------------------------- ### Attribute from Web Data Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Handle web-to-app user attribution using provided `apphudUserId` and `userEmail`. The `webData` dictionary can use keys like `apphud_user_id` or `aph_user_id`, and `email` or `apphud_user_email`. A callback `OnWebAttributionComplete` is provided to handle the result. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class WebAttributionManager : MonoBehaviour { public void AttributeFromWebData(string apphudUserId, string userEmail) { var webData = new Dictionary { { "apphud_user_id", apphudUserId }, // Or "aph_user_id" { "email", userEmail } // Or "apphud_user_email" }; ApphudSDK.AttributeFromWeb(webData, OnWebAttributionComplete); } private void OnWebAttributionComplete(bool success, ApphudUser user) { if (success) { Debug.Log($"Web attribution successful for user: {user.UserId}"); // Check if user has premium access from web purchase if (ApphudSDK.HasPremiumAccess()) { Debug.Log("User has premium access from web purchase!"); UnlockPremiumContent(); } } else { Debug.Log("Web attribution failed - user not found or no matching web user"); } } private void UnlockPremiumContent() { // Grant premium access to the user } } ``` -------------------------------- ### Set AppsFlyer Attribution Data Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Submit attribution data from AppsFlyer. The `conversionData` dictionary should contain the data from AppsFlyer's conversion callback. The `appsFlyerId` is the AppsFlyer ID for the user. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class AttributionManager : MonoBehaviour { public void SetAppsFlyerAttribution(Dictionary conversionData, string appsFlyerId) { var attributionData = new ApphudAttributionData( rawData: conversionData, adNetwork: null, // Optional: override ad network channel: null, // Optional: override channel campaign: null, // Optional: override campaign adSet: null, // Optional: override ad set creative: null, // Optional: override creative keyword: null, // Optional: override keyword custom1: null, // Optional: custom parameter custom2: null // Optional: custom parameter ); ApphudSDK.SetAttribution( ApphudAttributionProvider.APPSFLYER, attributionData, identifier: appsFlyerId ); } } ``` -------------------------------- ### Set Branch Attribution Data Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Submit attribution data from Branch. The `branchParams` dictionary should contain the parameters received from Branch. ```csharp using System.Collections.Generic; using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class AttributionManager : MonoBehaviour { public void SetBranchAttribution(Dictionary branchParams) { var attributionData = new ApphudAttributionData(rawData: branchParams); ApphudSDK.SetAttribution(ApphudAttributionProvider.BRANCH, attributionData); } } ``` -------------------------------- ### Android Device Identifiers and Fallback Mode Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Collects Android device identifiers for attribution and checks if paywalls are loaded from a fallback JSON file. Requires AD_ID permission for Android 13+. ```csharp #if UNITY_ANDROID using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class AndroidFeaturesManager : MonoBehaviour { void Start() { // Collect device identifiers for attribution integrations // Requires AD_ID permission in manifest for Android 13+ ApphudSDK.CollectDeviceIdentifiers(); } public void CheckFallbackMode() { // Check if paywalls are loaded from fallback JSON file bool isFallback = ApphudSDK.IsFallbackMode(); if (isFallback) { Debug.Log("Running in fallback mode - using cached paywall data"); } } public void RefreshData() { // Refresh user data when app comes to foreground // Don't call on app launch - SDK does it automatically ApphudSDK.RefreshUserData((ApphudUser user) => { Debug.Log($"User data refreshed: {user.UserId}"); Debug.Log($"Premium access: {ApphudSDK.HasPremiumAccess()}"); }); } public void TrackPurchaseInObserverMode( ApphudProduct product, string paywallId, string placementId) { // For Observer Mode when using Apphud paywalls but handling purchases yourself string offerIdToken = null; if (product.SubscriptionOfferDetails != null && product.SubscriptionOfferDetails.Count > 0) { offerIdToken = product.SubscriptionOfferDetails[0].OfferToken; } ApphudSDK.TrackPurchase( product.ProductId, offerIdToken, paywallId, placementId ); } } #endif ``` -------------------------------- ### Set Built-in User Properties in Unity Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Set built-in user properties like email, name, age, and gender using ApphudSDK.SetUserProperty. The `setOnce` parameter determines if the property can be updated later. ```csharp using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class UserPropertiesManager : MonoBehaviour { public void SetUserProfile(string email, string name, int age, string gender) { // Built-in user properties ApphudSDK.SetUserProperty(ApphudUserPropertyKey.Email, email, setOnce: true); ApphudSDK.SetUserProperty(ApphudUserPropertyKey.Name, name, setOnce: false); ApphudSDK.SetUserProperty(ApphudUserPropertyKey.Age, age, setOnce: false); ApphudSDK.SetUserProperty(ApphudUserPropertyKey.Gender, gender, setOnce: false); // "male", "female", "other" ApphudSDK.SetUserProperty(ApphudUserPropertyKey.Phone, "+1234567890", setOnce: false); ApphudSDK.SetUserProperty(ApphudUserPropertyKey.Cohort, "onboarding_v2", setOnce: true); } // ... other methods } ``` -------------------------------- ### Set Firebase Attribution Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Set Firebase attribution. This method does not require any specific attribution data as Firebase handles it internally. ```csharp using Apphud.Unity.SDK; public class AttributionManager : MonoBehaviour { public void SetFirebaseAttribution() { // Firebase doesn't require attribution data ApphudSDK.SetAttribution(ApphudAttributionProvider.FIREBASE); } } ``` -------------------------------- ### Flush User Properties for Segmentation in Unity Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Force flush user properties to Apphud for immediate audience segmentation using ApphudSDK.ForceFlushUserProperties. A callback function is provided to log the success status. ```csharp using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class UserPropertiesManager : MonoBehaviour { // ... other methods public void FlushPropertiesForSegmentation() { // Force flush user properties for immediate audience segmentation ApphudSDK.ForceFlushUserProperties((bool success) => { Debug.Log($"User properties flushed: {success}"); }); } } ``` -------------------------------- ### Set Custom User Properties in Unity Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Define and set custom user properties with various data types (string, boolean, int, float) using ApphudUserPropertyKey.CustomProperty. Properties can be removed by setting their value to null. ```csharp using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class UserPropertiesManager : MonoBehaviour { // ... SetUserProfile method public void SetCustomProperties() { // Custom properties with different value types ApphudSDK.SetUserProperty( ApphudUserPropertyKey.CustomProperty("subscription_tier"), "premium", setOnce: false ); ApphudSDK.SetUserProperty( ApphudUserPropertyKey.CustomProperty("completed_tutorials"), true, setOnce: false ); ApphudSDK.SetUserProperty( ApphudUserPropertyKey.CustomProperty("level"), 15, setOnce: false ); ApphudSDK.SetUserProperty( ApphudUserPropertyKey.CustomProperty("score"), 1250.5f, setOnce: false ); // Remove a property by setting to null ApphudSDK.SetUserProperty( ApphudUserPropertyKey.CustomProperty("old_property"), null, setOnce: false ); } // ... other methods } ``` -------------------------------- ### Track Apple Search Ads Attribution Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Track Apple Search Ads attribution. This method should only be called on iOS platforms. ```csharp #if UNITY_IOS public void TrackAppleSearchAdsAttribution() { ApphudSDK.TrackAppleSearchAds(); } #endif ``` -------------------------------- ### Increment/Decrement User Properties in Unity Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Modify numeric custom properties by incrementing or decrementing their values using ApphudSDK.IncrementUserProperty. A negative value will decrement the property. ```csharp using Apphud.Unity.SDK; using Apphud.Unity.Domain; public class UserPropertiesManager : MonoBehaviour { // ... SetUserProfile and SetCustomProperties methods public void IncrementProperty() { // Increment numeric custom properties ApphudSDK.IncrementUserProperty( ApphudUserPropertyKey.CustomProperty("games_played"), 1 ); // Decrement by passing negative value ApphudSDK.IncrementUserProperty( ApphudUserPropertyKey.CustomProperty("credits"), -10 ); } // ... other methods } ``` -------------------------------- ### Update User ID Source: https://context7.com/apphud/apphudsdk-unity/llms.txt Updates the user ID in Apphud after a user logs in to your system. This is crucial for accurate user tracking and session management. ```csharp using Apphud.Unity.SDK; public class UserSessionManager : MonoBehaviour { public void OnUserLogin(string userId) { // Update user ID after user logs in to your system ApphudSDK.UpdateUserId(userId); } public void OnUserLogout() { // Clear current user session ApphudSDK.LogOut(); // Re-initialize SDK for new user ApphudSDK.Start("your_api_key", null); } public void InitializeWithDeferredPlacements() { // Call before Start to defer automatic placement fetching ApphudSDK.DeferPlacements(); // Initialize SDK ApphudSDK.Start("your_api_key", (user) => { Debug.Log($"SDK initialized without placements: {user.UserId}"); // Fetch placements manually when needed FetchPlacementsManually(); }); } private void FetchPlacementsManually() { ApphudSDK.FetchPlacements((placements, error) => { Debug.Log($"Placements loaded: {placements.Count}"); }); } public void DisableTracking() { // Call before Start to opt user out of tracking ApphudSDK.OptOutOfTracking(); ApphudSDK.Start("your_api_key", null); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.