### Track Purchase Event Example (Android) Source: https://docs.amply.tools/developer-guide/api-reference An example of tracking a 'purchase_completed' event with product details, price, and currency. ```kotlin amply.track("purchase_completed", mapOf( "product_id" to "SKU123", "price" to 29.99, "currency" to "USD" )) ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.amply.tools/user-guide/campaigns Perform an HTTP GET request to the current page URL with the 'ask' query parameter to dynamically query the documentation. The question should be specific and self-contained. Use this when the answer is not explicitly present, for clarification, or to retrieve related sections. ```http GET https://docs.amply.tools/user-guide/campaigns.md?ask= ``` -------------------------------- ### DataSetType Creation (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Examples of creating different DataSetType instances using the Companion object in Swift. ```APIDOC ## DataSetType Creation (iOS) ### Description Examples of creating different DataSetType instances using the Companion object in Swift. ### Code ```swift // Device let deviceType = DataSetType.Companion.shared.fromString(value: "@device", params: [:]) // Session let sessionType = DataSetType.Companion.shared.fromString(value: "@session", params: [:]) // Triggered Event let eventType = DataSetType.Companion.shared.fromString( value: "@triggeredEvent", params: ["eventName": "purchase_completed"] ) // Events let eventsType = DataSetType.Companion.shared.fromString(value: "@events", params: [:]) ``` ``` -------------------------------- ### Query Documentation API Source: https://docs.amply.tools/developer-guide/installation Make an HTTP GET request to the documentation URL with an 'ask' query parameter to get specific information. ```bash GET https://docs.amply.tools/developer-guide/installation.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.amply.tools/developer-guide To get information not directly on a page, make an HTTP GET request to the current page URL with the 'ask' query parameter. The question should be specific and in natural language. ```http GET https://docs.amply.tools/developer-guide.md?ask= ``` -------------------------------- ### Query Documentation with 'ask' Parameter Source: https://docs.amply.tools/user-guide/overview To get additional information not directly present on the page, perform an HTTP GET request with the 'ask' query parameter. The question should be specific and self-contained. ```http GET https://docs.amply.tools/user-guide/overview.md?ask= ``` -------------------------------- ### Full Amply SDK Configuration Source: https://docs.amply.tools/developer-guide/android-integration Configure the Amply SDK with API keys, default campaign data, and custom network endpoints. Use this for advanced setup or development overrides. ```kotlin val config = amplyConfig { api { appId = "your.app.id" apiKeyPublic = "your_public_key" apiKeySecret = "your_secret_key" } // Optional: Default campaign configuration (JSON string) defaultConfig = """{"campaigns": []}""" // Optional: Override endpoints for development network { configBaseUrl = "https://config.amply.tools" backendBaseUrl = "https://api.amply.tools" } } ``` -------------------------------- ### Track Detailed Event (Kotlin) Source: https://docs.amply.tools/user-guide/sessions-and-events Example of tracking a 'product_viewed' event with comprehensive contextual properties, following best practices for naming and specificity. ```kotlin // Good event design amply.track("product_viewed", mapOf( "product_id" to "12345", "product_name" to "Premium Widget", "category" to "widgets", "price" to 49.99, "currency" to "USD", "source" to "search_results" )) ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.amply.tools/user-guide Perform an HTTP GET request on the current page URL with the `ask` query parameter to dynamically query the documentation. The question should be specific, self-contained, and written in natural language. ```http GET https://docs.amply.tools/user-guide.md?ask= ``` -------------------------------- ### Add Amply SDK Dependency (CocoaPods) Source: https://docs.amply.tools/developer-guide/ios-integration Integrate the Amply SDK into your project by adding the 'AmplySDK' pod to your Podfile and running 'pod install'. ```ruby pod 'AmplySDK', '~> 0.2.1' ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.amply.tools/developer-guide/api-reference Perform an HTTP GET request on the current page URL with the `ask` query parameter to dynamically query the documentation. The question should be specific, self-contained, and written in natural language. Use this mechanism when the answer is not explicitly present, you need clarification, or want to retrieve related sections. ```http GET https://docs.amply.tools/developer-guide/api-reference.md?ask= ``` -------------------------------- ### Error Handling (Android) Source: https://docs.amply.tools/developer-guide/api-reference Example of handling potential exceptions during SDK operations on Android. ```APIDOC ## Error Handling (Android) ### Description Example of handling potential exceptions during SDK operations on Android. ### Code ```kotlin try { val data = amply.getDataSetSnapshot(DataSetType.Device) } catch (e: IllegalStateException) { // SDK not initialized } ``` ``` -------------------------------- ### Error Handling (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Example of handling potential errors during SDK operations on iOS. ```APIDOC ## Error Handling (iOS) ### Description Example of handling potential errors during SDK operations on iOS. ### Code ```swift do { let data = try await amply.getDataSetSnapshot(type: deviceType) } catch { print("Error: \(error)") } ``` ``` -------------------------------- ### Add iOS SDK Dependency via CocoaPods Source: https://docs.amply.tools/developer-guide/installation Add the Amply iOS SDK to your project's Podfile and run 'pod install'. ```ruby pod 'AmplySDK', '~> 0.1.7' ``` -------------------------------- ### Get Session Data Snapshot (Kotlin) Source: https://docs.amply.tools/user-guide/sessions-and-events Retrieve a snapshot of the current session's data, including the session counter. Useful for analytics. ```kotlin val sessionData = amply.getDataSetSnapshot(DataSetType.Session) // Returns: { "counter": 5 } ``` -------------------------------- ### Get Session Data Snapshot (Swift) Source: https://docs.amply.tools/user-guide/sessions-and-events Retrieve a snapshot of the current session's data on iOS. Requires async handling. ```swift let sessionData = try await amply.getDataSetSnapshot(type: .session) ``` -------------------------------- ### App Lifecycle Callbacks Source: https://docs.amply.tools/developer-guide/ios-integration Implement application lifecycle methods to manage session state. The SDK automatically handles session start and pause, but these callbacks can be used for manual control. ```swift func applicationDidBecomeActive(_ application: UIApplication) { // Session automatically resumes } func applicationDidEnterBackground(_ application: UIApplication) { // Session automatically pauses } ``` -------------------------------- ### Get Dataset Snapshots Source: https://docs.amply.tools/developer-guide/ios-integration Fetch snapshots of device, session, or triggered event data using async/await. Ensure the Amply SDK is initialized before calling these methods. ```swift Task { guard let amply = AppDelegate.getAmply() else { return } // Device data if let deviceType = DataSetType.Companion.shared.fromString(value: "@device", params: [:]) { let deviceData = try await amply.getDataSetSnapshot(type: deviceType) print("Device: \(deviceData)") } // Session data if let sessionType = DataSetType.Companion.shared.fromString(value: "@session", params: [:]) { let sessionData = try await amply.getDataSetSnapshot(type: sessionType) print("Session: \(sessionData)") } // Event data if let eventType = DataSetType.Companion.shared.fromString( value: "@triggeredEvent", params: ["eventName": "purchase_completed"] ) { let eventData = try await amply.getDataSetSnapshot(type: eventType) print("Event: \(eventData)") } } ``` -------------------------------- ### Get DataSet Snapshot (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Retrieve a snapshot of a specific dataset for debugging or preview purposes on iOS. Requires specifying the dataset type. ```swift func getDataSetSnapshot(type: DataSetType) async throws -> [String: Any] ``` -------------------------------- ### Get DataSet Snapshot (Android) Source: https://docs.amply.tools/developer-guide/api-reference Retrieve a snapshot of a specific dataset for debugging or preview purposes on Android. Requires specifying the dataset type. ```kotlin suspend fun getDataSetSnapshot(type: DataSetType): Map ``` -------------------------------- ### Get Recent Events Source: https://docs.amply.tools/developer-guide/ios-integration Retrieve a list of recent events with a specified limit. This method uses async/await and requires the Amply SDK to be initialized. ```swift Task { guard let amply = AppDelegate.getAmply() else { return } let events = try await amply.getRecentEvents(limit: 30) for event in events { print("\(event.name) at \(event.timestamp)") } } ``` -------------------------------- ### Track Amply Events from Activities Source: https://docs.amply.tools/developer-guide/android-integration Track events within Android Activities, accessing the Amply instance via the Application class. This example shows tracking in onCreate and a click handler. ```kotlin class MainActivity : AppCompatActivity() { private val amply by lazy { MyApplication.getAmply(this) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) amply.track("main_screen_opened") } fun onPurchaseClicked() { amply.track("purchase_clicked", mapOf( "product_id" to "12345", "price" to 29.99 )) } } ``` -------------------------------- ### Get Triggered Event Counters (Kotlin) Source: https://docs.amply.tools/user-guide/sessions-and-events Retrieve data for a specific triggered event, including its global and session counters. Useful for campaign logic. ```kotlin // Get triggered event data with counters val eventData = amply.getDataSetSnapshot( DataSetType.TriggeredEvent("purchase_completed") ) // Returns: { "name": "purchase_completed", "counter": 5, "sessionCounter": 2, ... } ``` -------------------------------- ### Get Amply Dataset Snapshot Source: https://docs.amply.tools/developer-guide/android-integration Retrieve snapshots of dataset information (Device, Session, or specific Triggered Events) within a coroutine. Requires appropriate lifecycle scope. ```kotlin import tools.amply.sdk.datasets.DataSetType // In a coroutine lifecycleScope.launch { // Device data val deviceData = amply.getDataSetSnapshot(DataSetType.Device) Log.d("Amply", "Device: $deviceData") // Session data val sessionData = amply.getDataSetSnapshot(DataSetType.Session) Log.d("Amply", "Session: $sessionData") // Event data val eventData = amply.getDataSetSnapshot( DataSetType.TriggeredEvent("purchase_completed") ) Log.d("Amply", "Event: $eventData") } ``` -------------------------------- ### Get Recent Events (Android) Source: https://docs.amply.tools/developer-guide/api-reference Retrieve a list of recent events stored locally on Android. Supports an optional limit for the number of events to fetch. ```kotlin suspend fun getRecentEvents(limit: Int = 30): List ``` -------------------------------- ### Get Recent Amply Events Source: https://docs.amply.tools/developer-guide/android-integration Retrieve a list of recent events tracked by the SDK, with an optional limit. This is useful for debugging or analysis within a coroutine. ```kotlin lifecycleScope.launch { val events = amply.getRecentEvents(limit = 30) events.forEach { event -> Log.d("Amply", "${event.name} at ${event.timestamp}") } } ``` -------------------------------- ### Get Recent Events (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Retrieve a list of recent events stored locally on iOS. Requires specifying the maximum number of events to fetch. ```swift func getRecentEvents(limit: Int32) async throws -> [EventInterface] ``` -------------------------------- ### Initialize Amply SDK (Android) Source: https://docs.amply.tools/developer-guide/api-reference Instantiate the main SDK class for tracking events and managing campaigns on Android. ```kotlin class Amply(config: AmplyConfig, application: Application) ``` -------------------------------- ### Initialize Amply SDK (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Instantiate the main SDK class for tracking events and managing campaigns on iOS. ```swift class Amply(config: AmplyConfig) ``` -------------------------------- ### Initialize Amply SDK in AppDelegate Source: https://docs.amply.tools/developer-guide/ios-integration Initialize the Amply SDK with your application's configuration details in the `AppDelegate`'s `didFinishLaunchingWithOptions` method. Ensure the SDK instance is accessible throughout the app. ```swift import UIKit import AmplySDK @main class AppDelegate: UIResponder, UIApplicationDelegate { private static var amplySDK: Amply? func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { let config = AmplyConfig( appId: "your.app.id", apiKeyPublic: "your_public_key", apiKeySecret: "your_secret_key", defaultConfig: nil ) AppDelegate.amplySDK = Amply(config: config) return true } static func getAmply() -> Amply? { return amplySDK } } ``` -------------------------------- ### Listen to System Events (Swift) Source: https://docs.amply.tools/user-guide/sessions-and-events Set up a listener to receive callbacks for system-generated events on iOS. Prints the event name. ```swift // iOS class MyListener: SystemEventsListener { func onEvent(event: EventInterface) { print("System event: \(event.name)") } } amply.setSystemEventsListener(listener: MyListener()) ``` -------------------------------- ### Initialize Amply SDK on iOS Source: https://docs.amply.tools/developer-guide/installation Configure and initialize the Amply SDK in your iOS application. Provide your App ID, public API key, and secret API key. ```swift import AmplySDK let config = AmplyConfig( appId: "your.app.id", apiKeyPublic: "your_public_key", apiKeySecret: "your_secret_key", defaultConfig: nil ) let amply = Amply(config: config) amply.track(event: "test_event") ``` -------------------------------- ### Configure Amply SDK (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Configure the Amply SDK using a Swift initializer. Provide application ID, API keys, and network endpoints. ```swift let config = AmplyConfig( appId: String, apiKeyPublic: String, apiKeySecret: String, defaultConfig: String?, configBaseUrl: String?, backendBaseUrl: String? ) ``` -------------------------------- ### Initialize Amply SDK Source: https://docs.amply.tools/developer-guide/android-integration Initialize the Amply SDK in your Application class. Ensure you replace placeholder values with your actual app ID and API keys. ```kotlin import android.app.Application import tools.amply.sdk.Amply import tools.amply.sdk.config.amplyConfig class MyApplication : Application() { lateinit var amply: Amply private set override fun onCreate() { super.onCreate( val config = amplyConfig { api { appId = "your.app.id" apiKeyPublic = "your_public_key" apiKeySecret = "your_secret_key" } } amply = Amply(config, this) } companion object { fun getAmply(context: Context): Amply { return (context.applicationContext as MyApplication).amply } } } ``` -------------------------------- ### Amply SDK Full Configuration Options Source: https://docs.amply.tools/developer-guide/ios-integration Configure the Amply SDK with optional parameters for base URLs for configuration and backend services, in addition to standard app and API keys. ```swift let config = AmplyConfig( appId: "your.app.id", apiKeyPublic: "your_public_key", apiKeySecret: "your_secret_key", defaultConfig: nil, // Optional: default campaign JSON configBaseUrl: "https://config.amply.tools", // Optional: override backendBaseUrl: "https://api.amply.tools" // Optional: override ) ``` -------------------------------- ### Create DataSetType instances in Swift Source: https://docs.amply.tools/developer-guide/api-reference Demonstrates how to create instances of DataSetType using the Companion object in Swift for different dataset types like Device, Session, TriggeredEvent, and Events. ```swift // Device let deviceType = DataSetType.Companion.shared.fromString(value: "@device", params: [:]) // Session let sessionType = DataSetType.Companion.shared.fromString(value: "@session", params: [:]) // Triggered Event let eventType = DataSetType.Companion.shared.fromString( value: "@triggeredEvent", params: ["eventName": "purchase_completed"] ) // Events let eventsType = DataSetType.Companion.shared.fromString(value: "@events", params: [:]) ``` -------------------------------- ### Access SDK Version Constant Source: https://docs.amply.tools/developer-guide/api-reference Shows how to access the SDK version constant. ```kotlin AmplySDKInterface.VERSION // e.g., "1.0.0" ``` -------------------------------- ### Listen to System Events (Kotlin) Source: https://docs.amply.tools/user-guide/sessions-and-events Set up a listener to receive callbacks for system-generated events on Android. Logs the event name. ```kotlin // Android amply.setSystemEventsListener { event -> Log.d("Amply", "System event: ${event.name}") } ``` -------------------------------- ### Initialize Amply SDK on Android Source: https://docs.amply.tools/developer-guide/installation Configure and initialize the Amply SDK in your Android Application class. Ensure your App ID, public API key, and secret API key are correctly set. ```kotlin import tools.amply.sdk.Amply import tools.amply.sdk.config.amplyConfig // In your Application class val config = amplyConfig { api { appId = "your.app.id" apiKeyPublic = "your_public_key" apiKeySecret = "your_secret_key" } } val amply = Amply(config, application) amply.track("test_event") ``` -------------------------------- ### Add Snapshot Repository Configuration Source: https://docs.amply.tools/developer-guide/installation Configure your repositories to include the snapshot repository if you are using snapshot versions of the SDK. ```kotlin repositories { mavenCentral() // For snapshots maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") } ``` -------------------------------- ### Track Event with Properties (Kotlin) Source: https://docs.amply.tools/user-guide/sessions-and-events Track a user action with associated contextual data, such as item details for a purchase. ```kotlin amply.track("item_purchased", mapOf( "item_id" to "SKU123", "price" to 29.99, "currency" to "USD" )) ``` -------------------------------- ### SDK Initialization Properties Source: https://docs.amply.tools/developer-guide/api-reference Properties required for initializing the Amply SDK. ```APIDOC ## SDK Initialization Properties ### Description Properties required for initializing the Amply SDK. ### Parameters #### Request Body - **appId** (String) - Required - Application identifier - **apiKeyPublic** (String) - Required - Public API key - **apiKeySecret** (String) - Required - Secret API key - **defaultConfig** (String?) - Optional - Default campaign config JSON - **configBaseUrl** (String?) - Optional - Config server URL override - **backendBaseUrl** (String?) - Optional - Backend server URL override ``` -------------------------------- ### Listen for SDK System Events Source: https://docs.amply.tools/developer-guide/ios-integration Implement the SystemEventsListener protocol to receive and handle SDK system events. Ensure a strong reference to the adapter is maintained to prevent deallocation. ```swift class SystemEventsAdapter: NSObject, SystemEventsListener { func onEvent(event: EventInterface) { print("System event: \(event.name)") switch event.name { case "SDK_INITIALIZED": onSdkReady() case "CAMPAIGNS_LOADED": onCampaignsReady() case "SESSION_START": onSessionStart() default: break } } } // Register let adapter = SystemEventsAdapter() amply.setSystemEventsListener(listener: adapter) ``` -------------------------------- ### Handle SDK Initialization Error on Android Source: https://docs.amply.tools/developer-guide/api-reference Demonstrates how to catch an IllegalStateException if the SDK has not been initialized before calling getDataSetSnapshot. ```kotlin try { val data = amply.getDataSetSnapshot(DataSetType.Device) } catch (e: IllegalStateException) { // SDK not initialized } ``` -------------------------------- ### Listen for Amply System Events Source: https://docs.amply.tools/developer-guide/android-integration Set a listener to receive system events from the Amply SDK, such as initialization status or campaign loading. ```kotlin amply.setSystemEventsListener { event -> Log.d("Amply", "System event: ${event.name}") when (event.name) { "SDK_INITIALIZED" -> onSdkReady() "CAMPAIGNS_LOADED" -> onCampaignsReady() "SESSION_START" -> onSessionStart() } } ``` -------------------------------- ### Configure Amply SDK (Android DSL) Source: https://docs.amply.tools/developer-guide/api-reference Configure the Amply SDK using a Kotlin DSL builder for Android. Set application ID, API keys, and network endpoints. ```kotlin val config = amplyConfig { api { appId = "your.app.id" apiKeyPublic = "your_public_key" apiKeySecret = "your_secret_key" } defaultConfig = null // Optional JSON string network { configBaseUrl = "https://config.amply.tools" backendBaseUrl = "https://api.amply.tools" } } ``` -------------------------------- ### Handle SDK Initialization Error on iOS Source: https://docs.amply.tools/developer-guide/api-reference Shows how to handle potential errors when calling getDataSetSnapshot on iOS, typically related to SDK initialization. ```swift do { let data = try await amply.getDataSetSnapshot(type: deviceType) } catch { print("Error: \(error)") } ``` -------------------------------- ### Track Simple Event (Kotlin) Source: https://docs.amply.tools/user-guide/sessions-and-events Track a basic user action or system occurrence without additional properties. ```kotlin amply.track("screen_viewed") ``` -------------------------------- ### Track Basic Events with Amply SDK Source: https://docs.amply.tools/developer-guide/ios-integration Track simple events or events with associated properties using the `track` method of the Amply SDK instance. Ensure the SDK is initialized before tracking. ```swift guard let amply = AppDelegate.getAmply() else { return } // Simple event amply.track(event: "OnboardingStarted") // Event with properties amply.track(event: "ButtonTapped", properties: [ "name": "purchase_btn", "screen": "PaywallCoffee2" ]) ``` -------------------------------- ### Track Event with Properties (Swift) Source: https://docs.amply.tools/user-guide/sessions-and-events Track a user action with associated contextual data on iOS, such as item details for a purchase. ```swift amply.track(event: "item_purchased", properties: [ "item_id": "SKU123", "price": 29.99, "currency": "USD" ]) ``` -------------------------------- ### Track Basic Amply Events Source: https://docs.amply.tools/developer-guide/android-integration Track simple events or events with custom properties using the amply.track() method. Properties should be provided as a Map. ```kotlin // Simple event amply.track("screen_viewed") // Event with properties amply.track("button_clicked", mapOf( "button_id" to "purchase_btn", "screen" to "product_detail" )) ``` -------------------------------- ### SwiftUI App Lifecycle Integration Source: https://docs.amply.tools/developer-guide/ios-integration Adapt your SwiftUI app's lifecycle to use the `AppDelegate` for SDK initialization by using the `@UIApplicationDelegateAdaptor` property wrapper. ```swift import SwiftUI import AmplySDK @main struct MyApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } } } ``` -------------------------------- ### Set System Events Listener (Android) Source: https://docs.amply.tools/developer-guide/api-reference Register a listener for SDK system events on Android. This allows you to monitor events like SDK initialization, session start/end, and campaign loading. ```kotlin fun setSystemEventsListener(listener: SystemEventsListener) ``` -------------------------------- ### Set System Events Listener (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Register a listener for SDK system events on iOS. This allows you to monitor events like SDK initialization, session start/end, and campaign loading. ```swift func setSystemEventsListener(listener: SystemEventsListener) ``` -------------------------------- ### Add Amply SDK Dependency (Swift Package Manager) Source: https://docs.amply.tools/developer-guide/ios-integration Add the Amply SDK to your Xcode project using Swift Package Manager by providing the repository URL. ```swift dependencies: [ .package(url: "https://github.com/amply-tools/amply-sdk-ios", from: "0.2.1") ] ``` -------------------------------- ### Retrieve Recent Events (Kotlin) Source: https://docs.amply.tools/user-guide/sessions-and-events Fetches the last 30 events and prints their names and timestamps. Ensure the Amply SDK is initialized. ```kotlin // Get last 30 events val recentEvents = amply.getRecentEvents(limit = 30) recentEvents.forEach { event -> println("${event.name} at ${event.timestamp}") } ``` -------------------------------- ### Add iOS SDK Dependency via Package.swift Source: https://docs.amply.tools/developer-guide/installation Integrate the Amply iOS SDK into your project by adding the dependency to your Package.swift file. ```swift dependencies: [ .package(url: "https://github.com/amply-tools/amply-sdk-ios", from: "0.1.7") ] ``` -------------------------------- ### Handle Deep Links on Android Source: https://docs.amply.tools/user-guide/campaigns Register a listener in your Android application to intercept and handle deep links initiated by Amply campaigns. Return true if the deep link is handled. ```kotlin // Android amply.registerDeepLinkListener { url, info -> // Handle the deep link when { url.startsWith("myapp://promo") -> showPromoScreen(url) url.startsWith("myapp://settings") -> openSettings() else -> false // Not handled } true // Handled } ``` -------------------------------- ### Implement Deep Link Listener Protocol Source: https://docs.amply.tools/developer-guide/ios-integration Define a `DeepLinkHandler` protocol and create a `DeepLinkAdapter` class to conform to `DeepLinkListener`, enabling custom handling of deep links within your application. ```swift protocol DeepLinkHandler: AnyObject { func handleDeepLink(url: String, info: [String: Any]) -> Bool } class DeepLinkAdapter: NSObject, DeepLinkListener { private weak var handler: DeepLinkHandler? init(handler: DeepLinkHandler) { super.init() self.handler = handler } func onDeepLink(url: String, info: [String: Any]) -> Bool { return handler?.handleDeepLink(url: url, info: info) ?? false } } ``` -------------------------------- ### Track Simple Event (Swift) Source: https://docs.amply.tools/user-guide/sessions-and-events Track a basic user action or system occurrence without additional properties on iOS. ```swift amply.track(event: "screen_viewed") ``` -------------------------------- ### Register Deep Link Listener in AppDelegate Source: https://docs.amply.tools/developer-guide/ios-integration Register the `DeepLinkAdapter` with the Amply SDK in your `AppDelegate` to receive and handle incoming deep links. Implement the `handleDeepLink` method to process specific URL schemes. ```swift class AppDelegate: UIResponder, UIApplicationDelegate, DeepLinkHandler { private var deepLinkAdapter: DeepLinkAdapter? func application(...) -> Bool { // ... SDK init ... // Register deep link listener deepLinkAdapter = DeepLinkAdapter(handler: self) AppDelegate.amplySDK?.registerDeepLinkListener(listener: deepLinkAdapter!) return true } func handleDeepLink(url: String, info: [String: Any]) -> Bool { if url.hasPrefix("myapp://promo/") { let promoId = String(url.dropFirst("myapp://promo/".count)) showPromoScreen(promoId: promoId) return true } return false } } ``` -------------------------------- ### Register Application Class in Manifest Source: https://docs.amply.tools/developer-guide/android-integration Register your custom Application class in the AndroidManifest.xml file. ```xml ``` -------------------------------- ### Track Amply Events from Compose Source: https://docs.amply.tools/developer-guide/android-integration Track events from Jetpack Compose UI elements. Pass the Amply instance to your Composable functions. ```kotlin @Composable fun PurchaseButton(amply: Amply) { Button(onClick = { amply.track("purchase_clicked") }) { Text("Purchase") } } ``` -------------------------------- ### Add Kotlin Multiplatform SDK Dependency Source: https://docs.amply.tools/developer-guide/installation Include the Amply KMP SDK in your commonMain dependencies for Kotlin Multiplatform projects. ```kotlin kotlin { sourceSets { val commonMain by getting { dependencies { implementation("tools.amply:sdk-kmp:0.1.7") } } } } ``` -------------------------------- ### Add Android SDK Dependency (Kotlin DSL) Source: https://docs.amply.tools/developer-guide/installation Include the Amply Android SDK in your app's build.gradle.kts file for Kotlin projects. ```kotlin dependencies { implementation("tools.amply:sdk-android:0.1.7") } ``` -------------------------------- ### Track Custom Event in Kotlin Source: https://docs.amply.tools/user-guide/overview Use this to track custom events with associated properties. Events are timestamped, stored locally, and batched for server transmission. ```kotlin amply.track("button_clicked", mapOf("button_id" to "purchase")) ``` -------------------------------- ### Handle Deep Links on iOS Source: https://docs.amply.tools/user-guide/campaigns Implement a DeepLinkListenerDelegate on iOS to manage incoming deep links from campaigns. Return true to indicate the deep link was successfully processed. ```swift // iOS class DeepLinkHandler: DeepLinkListenerDelegate { func onDeepLink(url: String, info: [String: Any]) -> Bool { if url.hasPrefix("myapp://promo") { showPromoScreen(url: url) return true } return false } } amply.registerDeepLinkListener(listener: DeepLinkHandler()) ``` -------------------------------- ### Handle Deep Links in Activity Source: https://docs.amply.tools/developer-guide/android-integration Handle external deep links within an Activity by checking the intent data. Implement your navigation logic in the handleDeepLink function. ```kotlin class DeepLinkActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) intent?.data?.let { uri -> // Handle external deep links handleDeepLink(uri.toString()) } } private fun handleDeepLink(url: String) { // Your navigation logic } } ``` -------------------------------- ### SystemEventsListener Interface (Android) Source: https://docs.amply.tools/developer-guide/api-reference Interface for receiving SDK system events on Android. Implement this to react to various SDK lifecycle events. ```kotlin interface SystemEventsListener { fun onEvent(event: EventInterface) } ``` -------------------------------- ### Add Android SDK Dependency (Groovy) Source: https://docs.amply.tools/developer-guide/installation Include the Amply Android SDK in your app's build.gradle file for Groovy projects. ```groovy dependencies { implementation 'tools.amply:sdk-android:0.1.7' } ``` -------------------------------- ### Track Events from SwiftUI Views Source: https://docs.amply.tools/developer-guide/ios-integration Track events originating from SwiftUI views, such as button taps, by accessing the Amply SDK instance and invoking the `track` method within the button's action closure. ```swift struct PurchaseButton: View { var body: some View { Button("Purchase") { AppDelegate.getAmply()?.track(event: "OnboardingStarted") } } } ``` -------------------------------- ### Add Advertising ID Dependency Source: https://docs.amply.tools/developer-guide/android-integration Include this dependency in your `build.gradle.kts` file to enable the collection of Google Advertising ID. The SDK automatically collects this ID when available. ```kotlin dependencies { implementation("com.google.android.gms:play-services-ads-identifier:18.0.1") } ``` -------------------------------- ### Register Deep Link Listener Source: https://docs.amply.tools/developer-guide/android-integration Register a listener to handle deep links received by the SDK. The listener should return true if the deep link was handled. ```kotlin amply.registerDeepLinkListener { url, info -> Log.d("Amply", "Deep link received: $url") when { url.startsWith("myapp://promo/") -> { val promoId = url.removePrefix("myapp://promo/") openPromoScreen(promoId) true } url.startsWith("myapp://settings") -> { openSettings() true } else -> false // Not handled } } ``` -------------------------------- ### Target iOS Users Source: https://docs.amply.tools/user-guide/campaigns Use this JSON structure to define a targeting rule that selects users on the iOS platform. ```json { "==": [{ "var": "@device.platform" }, "iOS"] } ``` -------------------------------- ### registerDeepLinkListener Source: https://docs.amply.tools/developer-guide/api-reference Registers a listener to receive callbacks when a deep link action from a campaign is triggered. ```APIDOC ## registerDeepLinkListener ### Description Registers a listener for deep link actions from campaigns. ### Signature ```kotlin fun registerDeepLinkListener(listener: DeepLinkListener) ``` ```swift func registerDeepLinkListener(listener: DeepLinkListener) ``` ### Parameters #### Path Parameters - **listener** (DeepLinkListener) - Required - Callback for deep link events ### DeepLinkListener Interface ```kotlin interface DeepLinkListener { fun onDeepLink(url: String, info: Map): Boolean } ``` Returns `true` if the deep link was handled, `false` otherwise. ``` -------------------------------- ### Retrieve Recent Events (Swift) Source: https://docs.amply.tools/user-guide/sessions-and-events Fetches the last 30 events and prints their names and timestamps. Requires Swift concurrency features. ```swift // iOS let events = try await amply.getRecentEvents(limit: 30) for event in events { print("\(event.name) at \(event.timestamp)") } ``` -------------------------------- ### Register Deep Link Listener (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Register a listener to handle deep link actions from campaigns on iOS. The listener will be invoked when a deep link is encountered. ```swift func registerDeepLinkListener(listener: DeepLinkListener) ``` -------------------------------- ### track Source: https://docs.amply.tools/developer-guide/api-reference Tracks a custom event with optional properties. This method allows you to log specific user actions or occurrences within your application. ```APIDOC ## track ### Description Tracks a custom event with optional properties. ### Signature ```kotlin fun track(event: String, properties: Map = emptyMap()) ``` ```swift func track(event: String, properties: [String: Any] = [:]) ``` ### Parameters #### Path Parameters - **event** (String) - Required - The event name - **properties** (Map) - Optional - Event properties ### Request Example ```kotlin amply.track("purchase_completed", mapOf( "product_id" to "SKU123", "price" to 29.99, "currency" to "USD" )) ``` ``` -------------------------------- ### Register Deep Link Listener (Android) Source: https://docs.amply.tools/developer-guide/api-reference Register a listener to handle deep link actions from campaigns on Android. The listener will be invoked when a deep link is encountered. ```kotlin fun registerDeepLinkListener(listener: DeepLinkListener) ``` -------------------------------- ### Track Events from View Controllers Source: https://docs.amply.tools/developer-guide/ios-integration Track user interactions within `UIViewController` subclasses, such as screen views or button taps, by accessing the Amply SDK instance and calling the `track` method. ```swift class ProductViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated)n AppDelegate.getAmply()?.track(event: "product_screen_viewed") } @IBAction func purchaseButtonTapped(_ sender: UIButton) { AppDelegate.getAmply()?.track(event: "PurchaseFinished", properties: [ "product_id": "com.example.app.sub.01y", "price": 29.99, "currency": "USD" ]) } } ``` -------------------------------- ### Track Custom Event (Android) Source: https://docs.amply.tools/developer-guide/api-reference Track a custom event with optional properties on Android. Use this to log specific user actions or occurrences within your application. ```kotlin fun track(event: String, properties: Map = emptyMap()) ``` -------------------------------- ### Target Users with 3+ Sessions Source: https://docs.amply.tools/user-guide/campaigns Define a targeting rule to include users who have completed at least 3 sessions. This uses the session counter dataset. ```json { ">=": [{ "var": "@session.counter" }, 3] } ``` -------------------------------- ### setSystemEventsListener Source: https://docs.amply.tools/developer-guide/api-reference Registers a listener to receive notifications for SDK system events, such as initialization or session changes. ```APIDOC ## setSystemEventsListener ### Description Registers a listener for SDK system events. ### Signature ```kotlin fun setSystemEventsListener(listener: SystemEventsListener) ``` ```swift func setSystemEventsListener(listener: SystemEventsListener) ``` ### Parameters #### Path Parameters - **listener** (SystemEventsListener) - Required - Callback for system events ### SystemEventsListener Interface ```kotlin interface SystemEventsListener { fun onEvent(event: EventInterface) } ``` ### System Events | Event Name | | ------------------ | | `SDK_INITIALIZED` | | `SESSION_START` | | `SESSION_END` | | `CAMPAIGNS_LOADED` | ``` -------------------------------- ### DeepLinkListener Interface (Android) Source: https://docs.amply.tools/developer-guide/api-reference Interface for handling deep link events on Android. Implement this to process incoming deep links and their associated data. ```kotlin interface DeepLinkListener { fun onDeepLink(url: String, info: Map): Boolean } ``` -------------------------------- ### Track Custom Event (iOS) Source: https://docs.amply.tools/developer-guide/api-reference Track a custom event with optional properties on iOS. Use this to log specific user actions or occurrences within your application. ```swift func track(event: String, properties: [String: Any] = [:]) ``` -------------------------------- ### getDataSetSnapshot Source: https://docs.amply.tools/developer-guide/api-reference Retrieves a snapshot of a specific dataset, typically used for debugging or previewing data within the SDK. ```APIDOC ## getDataSetSnapshot ### Description Retrieves a snapshot of a dataset for debugging or preview. ### Signature ```kotlin suspend fun getDataSetSnapshot(type: DataSetType): Map ``` ```swift func getDataSetSnapshot(type: DataSetType) async throws -> [String: Any] ``` ### Parameters #### Path Parameters - **type** (DataSetType) - Required - The dataset type to retrieve ``` -------------------------------- ### Target Specific Android OS Versions Source: https://docs.amply.tools/user-guide/campaigns This JSON rule targets Android users on OS version 12 or higher, combining platform and version checks. ```json { "and": [ { "==": [{ "var": "@device.platform" }, "Android"] }, { ">=": [{ "var": "@device.osVersion" }, "12"] } ] } ``` -------------------------------- ### getRecentEvents Source: https://docs.amply.tools/developer-guide/api-reference Retrieves a list of recent events stored locally by the SDK, useful for debugging or offline analysis. ```APIDOC ## getRecentEvents ### Description Retrieves recent events from local storage. ### Signature ```kotlin suspend fun getRecentEvents(limit: Int = 30): List ``` ```swift func getRecentEvents(limit: Int32) async throws -> [EventInterface] ``` ### Parameters #### Path Parameters - **limit** (Int) - Optional - Default: 30 - Maximum events to return ### Returns List of `EventInterface` objects, newest first. ``` -------------------------------- ### Define EventInterface in Kotlin Source: https://docs.amply.tools/developer-guide/api-reference Defines the interface for an event, specifying its name, timestamp, properties, and type. ```kotlin interface EventInterface { val name: String val timestamp: Long val properties: Map val type: EventType } ``` -------------------------------- ### Define DataSetType in Kotlin Source: https://docs.amply.tools/developer-guide/api-reference Defines the sealed class for dataset types used in rule evaluation, including Device, User, Session, TriggeredEvent, and Events. ```kotlin sealed class DataSetType { object Device : DataSetType() object User : DataSetType() object Session : DataSetType() data class TriggeredEvent( val eventName: String?, val params: List, val countStrategy: CountStrategy ) : DataSetType() data class Events(val data: List) : DataSetType() companion object { fun fromString(value: String, params: Map = emptyMap()): DataSetType? } } ``` -------------------------------- ### Define EventType enum in Kotlin Source: https://docs.amply.tools/developer-guide/api-reference Defines the enum for event types, distinguishing between CUSTOM and SYSTEM events. ```kotlin enum class EventType { CUSTOM, SYSTEM } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.