### Started Checkout Event Source: https://docs.localytics.com/dev/tvOS Tracks when a user initiates the checkout process. Helps in measuring the effectiveness of the checkout flow. ```APIDOC ## POST /events/start_checkout ### Description Tracks when a user begins the checkout process. This event helps identify where users might be dropping off before completing a purchase. ### Method POST ### Endpoint /events/start_checkout ### Parameters #### Request Body - **totalPrice** (number) - Required - The total value of items in the cart at the start of checkout. - **itemCount** (integer) - Required - The total number of items in the cart. - **attributes** (object) - Optional - Custom key-value pairs for additional event data. ``` -------------------------------- ### Install Localytics SDK for tvOS using CocoaPods Source: https://docs.localytics.com/dev/tvOS Steps to install the Localytics SDK in a tvOS project via CocoaPods. This involves installing CocoaPods, initializing a Podfile, adding the Localytics-tvOS pod, and installing the pod. Ensure to open the .xcworkspace file after installation. ```bash gem install cocoapods pod init platform :tvos, '9.0' pod 'Localytics-tvOS', '~> 1.0' pod install ``` -------------------------------- ### Install Localytics SDK via NuGet Source: https://docs.localytics.com/dev/windows Installs the Localytics SDK package into your Windows project using the Package Manager Console in Visual Studio. This is the recommended method for quick integration. ```powershell Install-Package Localytics ``` -------------------------------- ### Standard Events: Started Checkout Source: https://docs.localytics.com/dev/react-native Tag a 'Started Checkout' event to track the initiation of a checkout process, including item count, total price, and optional attributes. ```APIDOC #### Started Checkout ```javascript LLLocalytics.tagStartedCheckout({ 'itemCount': 50, 'totalPrice': 2, 'attributes': { 'extraAttributeKey': 'extraAttributeValue' } }); ``` ``` -------------------------------- ### Tag Started Checkout Event Source: https://docs.localytics.com/dev/tvOS Tracks the initiation of the checkout process. Requires the total price and item count, along with optional attributes. ```Objective-C [Localytics tagStartedCheckout:@50 itemCount:@2 attributes:extraAttributes]; ``` ```Swift Localytics.tagStartedCheckout(50, itemCount: 2, attributes: extraAttributes) ``` -------------------------------- ### Integration and Privacy Management Example (Swift) Source: https://docs.localytics.com/dev/ios Example demonstrating Localytics SDK auto-integration, pausing data uploading, and asynchronously checking and setting the privacy opt-out status based on a server-side verification. This covers scenarios where consent management is external to the client app. ```swift Localytics.pauseDataUploading(true) Localytics.autoIntegrate("YOUR-LOCALYTICS-APP-KEY", withLocalyticsOptions:[ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: 5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: 10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: 30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: 90 ], launchOptions: launchOptions) DispatchQueue(label: "com.example.privacy-check").async { //This will be available even when the end user is opted out. var customerId = Localytics.customerId() //Make a request to your servers to see if the end user is opted out. var isUserOptedOutOnServer Localytics.setPrivacyOptedOut(isUserOptedOutOnServer) Localytics.pauseDataUploading(false) } ``` -------------------------------- ### Integration and Privacy Management Example (Objective-C) Source: https://docs.localytics.com/dev/ios Example demonstrating Localytics SDK integration, pausing data uploading, and asynchronously checking and setting the privacy opt-out status based on a server-side verification. This covers scenarios where consent management is external to the client app. ```objective-c [Localytics pauseDataUploading:YES]; [Localytics integrate:@"YOUR-LOCALYTICS-APP-KEY" withLocalyticsOptions:@{ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: @5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: @10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: @30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: @90 } launchOptions:launchOptions]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //This will be available even when the end user is opted out. NSString *customerId = [Localytics customerId]; //Make a request to your servers to see if the end user is opted out. BOOL isUserOptedOutOnServer; [Localytics setPrivacyOptedOut:isUserOptedOutOnServer]; [Localytics pauseDataUploading:NO]; }); ``` -------------------------------- ### Ruby Hypermedia Client Example Source: https://docs.localytics.com/dev/query-api An example demonstrating how to interact with the Localytics API using a hypermedia approach with the HyperResource library in Ruby. This showcases the benefits of a hypermedia API for client development. ```ruby # Example using HyperResource library for Ruby # (Actual code would involve library-specific methods for API interaction) ``` -------------------------------- ### CommonJS Integration Setup for Localytics Source: https://docs.localytics.com/dev/web Configures a CommonJS-compatible integration for the Localytics Web SDK using browserify-shim. This involves adding specific configurations to the `package.json` file to manage the 'localytics' module. ```json "browserify-shim": { "localytics": "global:ll" }, "browserify": { "transform": [ "browserify-shim" ] } ``` -------------------------------- ### Install Localytics SDK with Cocoapods Source: https://docs.localytics.com/dev/ios Install the Localytics SDK using Cocoapods. This involves installing the cocoapods gem, creating a Podfile, adding the Localytics pod, and running 'pod install'. Ensure you open the .xcworkspace file after installation. ```bash sudo gem install cocoapods ``` ```bash pod init ``` ```ruby platform :ios, '9.0' pod 'Localytics', '~> 7.0.0' ``` ```bash pod install ``` -------------------------------- ### Basic Localytics Service Worker Setup Source: https://docs.localytics.com/dev/web Sets up a basic service worker to automatically handle Localytics functionalities like performance events, push messages, notifications, and deeplinking. Requires your app key and VAPID public key for initialization. ```javascript self.appKey = 'YOUR_APP_KEY'; self.importScripts('https://web.localytics.com/v4/worker.js'); ``` ```javascript ll('init', 'YOUR_APP_KEY', { workerPath: '/', workerName: 'worker.js', publicKey: 'YOUR_VAPID_PUBLIC_KEY_AS_DEFINED_IN_LOCALYTICS_DASHBOARD' }); ``` -------------------------------- ### Initialize Localytics SDK Source: https://docs.localytics.com/dev/web Initializes the Localytics SDK with necessary parameters for advanced integration. Requires 'workerPath', 'workerName', and 'publicKey' to be provided. These values are crucial for service worker communication and push notification setup. ```javascript ll('init', 'YOUR_APP_KEY', { workerPath: 'YOUR_WEB_SERVICE_WORKER_HOST', workerName: 'YOUR_WEB_SERVICE_WORKER_FILE_NAME', publicKey: 'YOUR_PUBLIC_KEY_AS_PROVIDED_TO_LOCALYTICS_DASHBOARD' }); ``` -------------------------------- ### Tagging Events with Attributes in Localytics Source: https://docs.localytics.com/dev/windows This code example shows how to tag an event in Localytics with associated attributes to provide context. It requires the Localytics SDK, an event name, and a dictionary of string key-value pairs for attributes. The output is a detailed event logged in Localytics. ```csharp System.Collections.Generic.Dictionary attributes = new System.Collections.Generic.Dictionary() { { "Item Name", "Stickers"} }; Localytics.TagEvent("Item Purchased", attributes); ``` -------------------------------- ### Query New Users by Acquisition Source (cURL) Source: https://docs.localytics.com/dev/query-api Queries the number of new users split by acquisition source using cURL. This command-line example sends a GET request to the Localytics API with specified app ID, metrics, dimensions, and conditions. It requires API keys for authentication and returns JSON data. ```bash curl --get 'https://api.localytics.com/v1/query' \ --user 'API_KEY:API_SECRET' \ --data 'app_id=APP_ID' \ --data 'metrics=users' \ --data 'dimensions=channel' \ --data-urlencode 'conditions={"day":["between","2015-01-01","2015-01-08"]}' ``` -------------------------------- ### Localytics Profile API Endpoints Example Source: https://docs.localytics.com/dev/profile-api Examples of URLs for accessing Localytics profiles, including global, app-specific, and customer-level endpoints. ```text https://profile.localytics.com/v1/profiles/:customer_id https://profile.localytics.com/v1/apps/:app_key/profiles/:customer_id https://profile.localytics.com/v1/customers/:customer_id https://profile.localytics.com/v1/apps/99009zz0099009z0-z00z90-z009-99z0-zz00-000999zz99/profiles/isa ``` -------------------------------- ### InstallId Source: https://docs.localytics.com/dev/maui Represents an installation identifier. ```APIDOC ## InstallId ### Description An installation identifier. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### Tag Started Checkout Event (Objective-C, Swift) Source: https://docs.localytics.com/dev/ios Tags a 'Started Checkout' event, capturing the total price and item count. This event signifies the beginning of the checkout process and helps in understanding user commitment to purchase. ```Objective-C [Localytics tagStartedCheckout:@50 itemCount:@2 attributes:extraAttributes]; ``` ```Swift Localytics.tagStartedCheckout(50, itemCount: 2, attributes: extraAttributes) ``` -------------------------------- ### Localytics Location Delegate Setup (Swift) Source: https://docs.localytics.com/dev/ios This Swift snippet demonstrates conforming your app delegate to the `LLLocationDelegate` protocol and setting the location delegate in `didFinishLaunchingWithOptions`. ```swift class AppDelegate: UIResponder, UIApplicationDelegate, LLLocationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { // ...Localytics initialization code here... Localytics.setLocationDelegate(self) // ... rest of didFinishLaunchingWithOptions ... return true } func localyticsDidUpdateLocation(_ location: CLLocation) { // ... do something } func localyticsDidUpdateMonitoredRegions(_ addedRegions: [LLRegion], remove removedRegions: [LLRegion]) { // ... do something } func localyticsDidTriggerRegions(_ regions: [LLRegion], with event: LLRegionEvent) { // ... do something } ``` -------------------------------- ### Install iOS Cocoapods for Localytics Source: https://docs.localytics.com/dev/react-native Installs the necessary Cocoapods for the Localytics SDK on iOS projects. ```bash cd iOS pod install ``` -------------------------------- ### Localytics Location Delegate Setup (Objective-C) Source: https://docs.localytics.com/dev/ios This Objective-C snippet shows how to conform your app delegate to the `LLLocationDelegate` protocol and set the location delegate in `didFinishLaunchingWithOptions`. ```objectivec @interface YourAppDelegate : UIResponder - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // ...Localytics initialization code here... [Localytics setLocationDelegate:self]; // ... rest of didFinishLaunchingWithOptions ... return YES; } - (void)localyticsDidUpdateLocation:(nonnull CLLocation *)location { // ... do something } - (void)localyticsDidUpdateMonitoredRegions:(nonnull NSArray *)addedRegions removeRegions:(nonnull NSArray *)removedRegions { // ... do something } - (void)localyticsDidTriggerRegions:(nonnull NSArray *)regions withEvent:(LLRegionEvent)event { // ... do something } ``` -------------------------------- ### Install Localytics SDK with Carthage Source: https://docs.localytics.com/dev/ios Integrate the Localytics SDK using Carthage by adding the binary repository to your Cartfile and running 'carthage update'. This method requires additional steps to link the framework and add a build phase. ```bash binary "https://downloads.localytics.com/SDKs/iOS/Localytics.json" ~> 7.0.0 ``` -------------------------------- ### GET /v1/query Source: https://docs.localytics.com/dev/query-api Retrieves data based on specified metrics, dimensions, and conditions. This example shows how to get the number of sessions per event within a specified date range. ```APIDOC ## GET /v1/query ### Description Retrieves aggregated data based on specified metrics, dimensions, and conditions. This endpoint is used for querying various analytics data points. ### Method GET ### Endpoint /v1/query ### Parameters #### Query Parameters - **app_id** (string) - Required - The unique identifier for the application. - **metrics** (string) - Required - The metric to retrieve (e.g., `sessions_per_event`). - **dimensions** (string) - Required - The dimension by which to group the metrics (e.g., `event_name`). - **conditions** (JSON string) - Optional - A JSON string specifying conditions for filtering the data. Example: `{"day":["between","2015-01-01","2015-01-08"]}`. ### Request Example ``` curl --get 'https://api.localytics.com/v1/query' \ --user 'API_KEY:API_SECRET' \ --data 'app_id=APP_ID' \ --data 'metrics=sessions_per_event' \ --data 'dimensions=event_name' \ --data-urlencode 'conditions={"day":["between","2015-01-01","2015-01-08"]}' ``` ### Response #### Success Response (200) - **results** (array) - An array of objects, where each object contains the requested dimensions and metrics. - **event_name** (string) - The name of the event. - **sessions_per_event** (integer) - The number of sessions associated with the event. - **app_id** (array) - The application ID. - **query** (object) - Details of the query executed. #### Response Example ```json { "results": [ { "event_name": "Added to Cart", "sessions_per_event": 10012 }, { "event_name": "Category Viewed", "sessions_per_event": 116472 } ], "app_id": [ "APP_ID" ], "query": { "metrics": [ "sessions_per_event" ], "dimensions": [ "event_name" ], "conditions": { "day": [ "between", "2015-01-01", "2015-01-08" ] } } } ``` ``` -------------------------------- ### Integrate Localytics SDK and Options (Objective-C, Swift) Source: https://docs.localytics.com/dev/ios Integrate the Localytics SDK with your unique app key and configure upload intervals for different network conditions. This method should be called at the start of application:didFinishLaunchingWithOptions:. ```Objective-C [Localytics integrate:@"YOUR-LOCALYTICS-APP-KEY" withLocalyticsOptions:@{ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: @5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: @10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: @30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: @90 }] if (application.applicationState != UIApplicationStateBackground) { [Localytics openSession]; } ``` ```Swift Localytics.integrate("YOUR-LOCALYTICS-APP-KEY", withLocalyticsOptions: [ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: 5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: 10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: 30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: 90 ]) if application.applicationState != .background { Localytics.openSession() } ``` -------------------------------- ### Getting Inbox Campaigns Source: https://docs.localytics.com/dev/react-native Methods to retrieve inbox campaigns that are available for display. ```APIDOC ## Get Displayable Inbox Campaigns ### Description Retrieves inbox campaigns that are available for display to the user. ### Method `LLLocalytics.getDisplayableInboxCampaigns()` ### Parameters None ### Request Example ```javascript LLLocalytics.getDisplayableInboxCampaigns().then((campaigns) => { try { // handle campaigns } catch(e) { console.error(e); } }); ``` ### Response #### Success Response (200) - **campaigns** (Array) - An array of displayable inbox campaign objects. ## Get All Inbox Campaigns ### Description Retrieves all inbox campaigns, including those that may have been deleted. ### Method `LLLocalytics.getAllInboxCampaigns()` ### Parameters None ### Request Example ```javascript LLLocalytics.getAllInboxCampaigns().then((campaigns) => { try { // handle campaigns } catch(e) { console.error(e); } }); ``` ### Response #### Success Response (200) - **campaigns** (Array) - An array of all inbox campaign objects. ``` -------------------------------- ### Handle Remote Notifications in didFinishLaunchingWithOptions (Objective-C) Source: https://docs.localytics.com/dev/ios Demonstrates how to handle remote notifications within the `application:didFinishLaunchingWithOptions:` method for manual integrations. This snippet is relevant for older SDK versions before specific updates. ```objective-c [[LocalyticsSession shared] handleRemoteNotification:[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]]; ``` -------------------------------- ### Install Localytics React Native npm Module Source: https://docs.localytics.com/dev/react-native Installs the Localytics React Native module using npm. Supports different versions of React Native, including those with and without AndroidX support. ```bash cd YourProjectDirectory npm install # For RN 0.60+ with androidX support: npm install -S localytics-react-native # For RN 0.59 and below: npm install -S localytics-react-native-legacy ``` -------------------------------- ### Multiple Instances Source: https://docs.localytics.com/dev/web This section explains how to initialize and use multiple instances of the Localytics Web SDK on the same page using namespaces. ```APIDOC ## Multiple Instances ### Description Allows initializing multiple instances of the Localytics Web SDK on the same page by using namespaces. You can use any alphanumeric string as a namespace name. ### Initializing Multiple Instances Initialize each instance with a unique namespace. For example, `ns1` and `ns2`. ```javascript ll('init.ns1', 'YOUR-LOCALYTICS-APP-KEY', {} /* Options */);ll('init.ns2', 'YOUR-LOCALYTICS-APP-KEY', {} /* Options */); ``` ### Calling SDK Methods with Namespaces Specify the matching namespace name in all subsequent SDK calls to target the correct instance. ```javascript ll('tagEvent.ns1', 'Some Event');ll('tagEvent.ns2', 'Another Event'); ``` ``` -------------------------------- ### Close Localytics Session (Objective-C, Swift) Source: https://docs.localytics.com/dev/tvOS Closes the current Localytics session. This method should be called at the start of applicationDidEnterBackground:. ```objectivec [Localytics closeSession]; ``` ```swift Localytics.closeSession() ``` -------------------------------- ### Initialize Localytics SDK (JavaScript) Source: https://docs.localytics.com/dev/web Shows the basic syntax for initializing the Localytics SDK with an app key and optional configuration options such as tracking page views and setting a custom domain. ```javascript ll('init', 'YOUR-LOCALYTICS-APP-KEY', {trackPageView: true, domain: 'localytics.com'}); ``` -------------------------------- ### Display LLInboxViewController with Loading Indicator (Objective-C) Source: https://docs.localytics.com/dev/ios This Objective-C code demonstrates how to instantiate `LLInboxViewController` programmatically and set its `showsActivityIndicatorView` property to `YES` before pushing it onto the navigation controller. This ensures the loading indicator is visible while campaigns load. ```Objective-C - (void)displayInbox { LLInboxViewController *inboxViewController = [[LLInboxViewController alloc] init]; inboxViewController.showsActivityIndicatorView = YES; [self.navigationController pushViewController:inboxViewController animated:YES]; } ``` -------------------------------- ### Open Localytics Session (Objective-C, Swift) Source: https://docs.localytics.com/dev/tvOS Opens a new Localytics session. This method should be called at the start of applicationDidBecomeActive: and applicationWillEnterForeground:. ```objectivec [Localytics openSession]; ``` ```swift Localytics.openSession() ``` -------------------------------- ### Tag 'Started Checkout' Event in Localytics Source: https://docs.localytics.com/dev/react-native Record when a user initiates the checkout process. This event tracks item count, total price, and custom attributes. ```javascript LLLocalytics.tagStartedCheckout({'itemCount': 50, 'totalPrice': 2, 'attributes': {'extraAttributeKey': 'extraAttributeValue'}}); ``` -------------------------------- ### Programmatically Display LLInboxViewController (Swift) Source: https://docs.localytics.com/dev/ios This Swift code snippet demonstrates how to programmatically initialize and push the LLInboxViewController onto a navigation controller stack. ```swift func displayInbox() { let inboxViewController = LLInboxViewController() self.navigationController?.pushViewController(inboxViewController, animated: true) } ``` -------------------------------- ### Get SDK Version (Localytics SDK) Source: https://docs.localytics.com/dev/react-native Returns the version of the Localytics SDK currently in use as a string. This is useful for debugging and ensuring compatibility with specific SDK features. ```javascript var sdkVersion = localytics.libraryVersion; // "iOSa_4.3.0" ``` -------------------------------- ### Initialize Localytics SDK v7 using Builder Pattern (Objective-C, Swift) Source: https://docs.localytics.com/dev/ios This snippet demonstrates the new builder-based initialization for the Localytics SDK v7. It replaces the older autoIntegrate approach and allows for detailed configuration of various SDK settings, including app key, launch options, logging, network intervals, and privacy settings. The builder pattern simplifies the integration process and offers granular control over SDK behavior. ```Objective-C [[[[[[[[[[[[[Localytics builder] settingAppKey:@"YOUR-LOCALYTICS-APP-KEY"] settingLaunchOptions:launchOptions] settingLoggingEnabled:YES] settingLocalyticsOptions:@{ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: @5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: @10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: @30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: @90 }] settingPauseDataUploading:NO] settingOptedOut:NO] settingPrivacyOptedOut:NO] settingTestModeEnabled:NO] settingLocationMonitoringEnabled:YES] settingLocationMonitoringPersist:YES] build] autoIntegrate]; ``` ```Swift Localytics.builder() .settingAppKey("YOUR-LOCALYTICS-APP-KEY") .settingLaunchOptions(launchOptions) .settingLoggingEnabled(false) .settingLocalyticsOptions([ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: 5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: 10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: 30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: 90 ]) .settingPauseDataUploading(false) .settingOptedOut(false) .settingPrivacyOptedOut(false) .settingTestModeEnabled(false) .settingLocationMonitoringEnabled(false) .settingLocationMonitoringPersist(false) .build() .autoIntegrate() ``` -------------------------------- ### Initialize Localytics SDK (Version Below 7.0.0) Source: https://docs.localytics.com/dev/ios Initializes the Localytics SDK with an app key and custom upload intervals for different network conditions. This method is for SDK versions prior to 7.0.0. ```objective-c [Localytics autoIntegrate:@"YOUR-LOCALYTICS-APP-KEY" withLocalyticsOptions:@{ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: @5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: @10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: @30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: @90 } launchOptions:launchOptions]; ``` ```swift Localytics.autoIntegrate("YOUR-LOCALYTICS-APP-KEY", withLocalyticsOptions:[ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: 5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: 10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: 30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: 90 ], launchOptions: launchOptions) ``` -------------------------------- ### Specify React Native Version in package.json Source: https://docs.localytics.com/dev/react-native Defines the React Native version dependency in the `package.json` file. The example shows version 0.71.4, which was verified with the Localytics SDK. ```json "dependencies": { ... "react-native": "0.71.4", ... } ``` -------------------------------- ### Initialize Multiple Localytics Instances Source: https://docs.localytics.com/dev/web Demonstrates how to initialize multiple instances of the Localytics Web SDK on the same page using namespaces. Each instance is initialized with a unique namespace name, allowing for independent tracking and management. ```javascript ll('init.ns1', 'YOUR-LOCALYTICS-APP-KEY', {} /* Options */);ll('init.ns2', 'YOUR-LOCALYTICS-APP-KEY', {} /* Options */); ``` -------------------------------- ### Open and Upload Session (Objective-C, Swift) Source: https://docs.localytics.com/dev/ios Open a new Localytics session and upload any pending events. This code should be added to the start of both applicationDidBecomeActive: and applicationWillEnterForeground:. ```Objective-C [Localytics openSession]; [Localytics upload]; ``` ```Swift Localytics.openSession() Localytics.upload() ``` -------------------------------- ### Get All Inbox Campaigns in React Native Source: https://docs.localytics.com/dev/react-native Retrieves all Inbox campaigns, including those that may have been deleted. This method returns a promise resolving with all campaigns. Use try-catch for robust error management. ```javascript LLLocalytics.getAllInboxCampaigns().then((campaigns) => { try { // handle campaigns } catch(e) { console.error(e); } }); ``` -------------------------------- ### Get Event Attributes (Localytics SDK) Source: https://docs.localytics.com/dev/react-native Returns a Javascript object containing the attribute keys and values associated with the event or trigger that launched the In-App message. This helps in understanding the context of the message trigger. ```javascript var eventAttributes = localytics.attributes; // {"Team Name": "Celtics", "City": "Boston"}; ``` -------------------------------- ### Get Custom Dimensions (Localytics SDK) Source: https://docs.localytics.com/dev/react-native Retrieves a Javascript object containing the current session's custom dimensions. The keys of the object are formatted as 'c0', 'c1', etc., corresponding to the dimensions that have been set. ```javascript var dimensions = localytics.customDimensions; // {"c0": "Paid", "c1": "Logged In"}; ``` -------------------------------- ### Basic Integration Initialization Source: https://docs.localytics.com/dev/web Initializes the Localytics Web SDK with web push configuration. Requires `workerPath`, `workerName`, and `publicKey`. ```APIDOC ## POST /init ### Description Initializes the Localytics Web SDK with web push configuration. Requires `workerPath`, `workerName`, and `publicKey`. ### Method POST ### Endpoint /init ### Parameters #### Request Body - **appKey** (string) - Required - Your Localytics application key. - **options** (object) - Required - Initialization options. - **workerPath** (string) - Required - The path to your service worker file. - **workerName** (string) - Required - The name of your service worker file. - **publicKey** (string) - Required - Your public VAPID key provided by the Localytics dashboard. ### Request Example ```json { "appKey": "YOUR_APP_KEY", "options": { "workerPath": "/", "workerName": "worker.js", "publicKey": "YOUR_PUBLIC_KEY_AS_PROVIDED_TO_LOCALYTICS_DASHBOARD" } } ``` ### Response #### Success Response (200) - **message** (string) - A success message indicating initialization. #### Response Example ```json { "message": "SDK initialized successfully." } ``` ``` -------------------------------- ### Programmatically Display LLInboxViewController (Objective-C) Source: https://docs.localytics.com/dev/ios This Objective-C code snippet demonstrates how to programmatically initialize and push the LLInboxViewController onto a navigation controller stack. ```objective-c - (void)displayInbox { LLInboxViewController *inboxViewController = [[LLInboxViewController alloc] init]; [self.navigationController pushViewController:inboxViewController animated:YES]; } ``` -------------------------------- ### Receiving Callbacks in Javascript Source: https://docs.localytics.com/dev/react-native Register for Localytics messaging callbacks to receive events related to the display of in-app messages, places campaigns, and push notifications. This setup is crucial for intercepting these events in your Javascript code. ```APIDOC ## Receiving callbacks in Javascript To start receiving Messaging Callbacks, you must first register for callbacks with Localytics: ```javascript var messagingEventListener; LLLocalytics.setAnalyticsEventsEnabled(true); if (Platform.OS === "ios") { messagingEventListener = new NativeEventEmitter(NativeModules.LLMessagingEmitter); } else { messagingEventListener = DeviceEventEmitter; } // Then simply begin listening for emitted events: messagingEventListener.addListener('localyticsShouldShowInAppMessage', (arg) => { // args = { "campaign": OBJECT, "shouldShow": BOOLEAN } // ... do something ... }); messagingEventListener.addListener('localyticsShouldDelaySessionStartInAppMessages', (arg) => { // args = { "shouldDelay": BOOLEAN } // ... do something ... }); messagingEventListener.addListener('localyticsWillDisplayInAppMessage', (arg) => { // args = { "campaign": OBJECT } // ... do something ... }); messagingEventListener.addListener('localyticsWillDismissInAppMessage', (arg) => { // args = { } // ... do something ... }); messagingEventListener.addListener('localyticsDidDismissInAppMessage', (arg) => { // args = { } // ... do something ... }); messagingEventListener.addListener('localyticsShouldDisplayPlacesCampaign', (arg) => { // args = { "campaign": OBJECT, "shouldShow": BOOLEAN } // ... do something ... }); messagingEventListener.addListener('localyticsWillShowPlacesPushNotification', (arg) => { // args = { "campaign": OBJECT } // ... do something ... }); messagingEventListener.addListener('localyticsShouldShowPushNotification', (arg) => { // args = { "campaign": OBJECT, "shouldShow": BOOLEAN } // ANDROID ONLY // ... do something ... }); messagingEventListener.addListener('localyticsWillShowPushNotification', (arg) => { // args = { "campaign": OBJECT } // ANDROID ONLY // ... do something ... }); messagingEventListener.addListener('localyticsDiyInAppMessage', (arg) => { // args = { "campaign": OBJECT } // ... Handle the rendering of your own In App campaign. This should be paired with the next section on Modifying Messaging Behavior ... }); messagingEventListener.addListener('localyticsDiyPlacesPushNotification', (arg) => { // args = { "campaign": OBJECT } // ... Handle the rendering of your own Places campaign. This should be paired with the next section on Modifying Messaging Behavior ... }); messagingEventListener.addListener('localyticsDiyPushNotification', (arg) => { // args = { "campaign": OBJECT } // ANDROID ONLY // ... Handle the rendering of your own Push campaign. This should be paired with the next section on Modifying Messaging Behavior ... }); ``` ``` -------------------------------- ### Initialize Localytics SDK (Version 7.0.0 and Above) Source: https://docs.localytics.com/dev/ios Initializes the Localytics SDK using a builder pattern, allowing configuration of app key, launch options, logging, upload intervals, and privacy settings. This method is for SDK versions 7.0.0 and above. ```objective-c [[[[[[[[[[[[[Localytics builder] settingAppKey:@"YOUR-LOCALYTICS-APP-KEY"] settingLaunchOptions:launchOptions] settingLoggingEnabled:YES] settingLocalyticsOptions:@{ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: @5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: @10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: @30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: @90 }] settingPauseDataUploading:NO] settingOptedOut:NO] settingPrivacyOptedOut:NO] settingTestModeEnabled:NO] settingLocationMonitoringEnabled:YES] settingLocationMonitoringPersist:YES] build] autoIntegrate]; ``` ```swift Localytics.builder() .settingAppKey("YOUR-LOCALYTICS-APP-KEY") .settingLaunchOptions(launchOptions) .settingLoggingEnabled(false) .settingLocalyticsOptions([ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: 5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: 10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: 30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: 90 ]) .settingPauseDataUploading(false) .settingOptedOut(false) .settingPrivacyOptedOut(false) .settingTestModeEnabled(false) .settingLocationMonitoringEnabled(false) .settingLocationMonitoringPersist(false) .build() .autoIntegrate() ``` -------------------------------- ### Get Unread Inbox Campaigns Count in React Native Source: https://docs.localytics.com/dev/react-native Retrieves the total count of unread Inbox campaigns. This function returns a promise that resolves with the unread count. Error handling should be implemented using try-catch. ```javascript LLLocalytics.getInboxCampaignsUnreadCount().then((count) => { try { // handle unread count } catch(e) { console.error(e); } }); ``` -------------------------------- ### Get Displayable Inbox Campaigns in React Native Source: https://docs.localytics.com/dev/react-native Retrieves a list of Inbox campaigns that are currently displayable to the user. This function returns a promise that resolves with an array of campaigns. Ensure proper error handling with try-catch. ```javascript LLLocalytics.getDisplayableInboxCampaigns().then((campaigns) => { try { // handle campaigns } catch(e) { console.error(e); } }); ``` -------------------------------- ### Integrate Localytics Web SDK Source: https://docs.localytics.com/dev/web Include this JavaScript snippet in the section of your HTML pages to initialize the Localytics SDK. This script loads the Localytics library and configures it with your unique application key. ```javascript + function(l, y, t, i, c, s) { l['LocalyticsGlobal'] = i; l[i] = function() { (l[i].q = l[i].q || []).push(arguments) }; l[i].t = +new Date; (s = y.createElement(t)).type = 'text/javascript'; s.src = '//web.localytics.com/v4/localytics.min.js'; (c = y.getElementsByTagName(t)[0]).parentNode.insertBefore(s, c); ll('init', 'YOUR-LOCALYTICS-APP-KEY', {} /* Options */ ); }(window, document, 'script', 'll'); ``` -------------------------------- ### Register Analytics Callbacks in Javascript Source: https://docs.localytics.com/dev/react-native This snippet demonstrates how to register for Localytics analytics callbacks in a Javascript environment, handling platform-specific emitter setup. It's used to receive notifications for session lifecycle events and custom analytics events. ```javascript var analyticsEventListener; LLLocalytics.setAnalyticsEventsEnabled(true); if (Platform.OS === "ios") { analyticsEventListener = new NativeEventEmitter(NativeModules.LLAnalyticsEmitter); } else { analyticsEventListener = DeviceEventEmitter; } analyticsEventListener.addListener('localyticsSessionWillOpen', (arg) => { // args = { isFirst: BOOLEAN, isUpgrade: BOOLEAN, isResume: BOOLEAN } // ... do something ... }); analyticsEventListener.addListener('localyticsSessionDidOpen', (arg) => { // args = { isFirst: BOOLEAN, isUpgrade: BOOLEAN, isResume: BOOLEAN } // ... do something ... }); analyticsEventListener.addListener('localyticsDidTagEvent', (arg) => { // args = {"name": STRING, "attributes": OBJECT, "customerValueIncrease": NUMBER}; // ... do something ... }); analyticsEventListener.addListener('localyticsSessionWillClose', (arg) => { // args = { } // ... do something ... }); ``` -------------------------------- ### Conform App Delegate to LLAnalyticsDelegate Protocol (Objective-C) Source: https://docs.localytics.com/dev/ios Shows how to make an app delegate conform to the `LLAnalyticsDelegate` protocol in Objective-C. This is a prerequisite for utilizing Localytics analytics callbacks. ```objective-c @interface YourAppDelegate : UIResponder ``` -------------------------------- ### Initialize Localytics SDK and Set Delegate Source: https://docs.localytics.com/dev/ios Initialize the Localytics SDK with your app key and configure upload intervals using `autoIntegrate`. Subsequently, set the analytics delegate to 'self' to enable custom event handling. This step requires your Localytics app key. ```objectivec [Localytics autoIntegrate:@"YOUR-LOCALYTICS-APP-KEY" withLocalyticsOptions:@{ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: @5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: @10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: @30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: @90 } launchOptions:launchOptions]; [Localytics setAnalyticsDelegate:self]; ``` ```swift Localytics.autoIntegrate("YOUR-LOCALYTICS-APP-KEY", withLocalyticsOptions:[ LOCALYTICS_WIFI_UPLOAD_INTERVAL_SECONDS: 5, LOCALYTICS_GREAT_NETWORK_UPLOAD_INTERVAL_SECONDS: 10, LOCALYTICS_DECENT_NETWORK_UPLOAD_INTERVAL_SECONDS: 30, LOCALYTICS_BAD_NETWORK_UPLOAD_INTERVAL_SECONDS: 90 ], launchOptions: launchOptions) Localytics.setAnalyticsDelegate(self) ``` -------------------------------- ### Ruby Example: Managing Localytics User Profiles Source: https://docs.localytics.com/dev/profile-api A Ruby script demonstrating how to interact with the Localytics Profile API using Net::HTTP. It covers creating, reading, updating, and deleting user profiles and their attributes. ```ruby # Using Ruby 2.1.2 require 'net/http' require 'json' # All REST methods are available at this endpoint: api_root = "https://profile.localytics.com/v1/profiles" # Let's call our customer "Isa." In production, of course, you should not use customer's real names or emails # to identify them, but instead use a secure non-guessable unique identifier like 47c44727-1c22-4dfd-a901-9d0dcf049c89. customer_id = "Isa" # Replace these with your real API key and secret: API_KEY = "MY_API_KEY" API_SECRET = "MY_API_SECRET" uri = URI("#{api_root}/#{customer_id}") Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| # Let's see if a profile for Isa exists: get_request = Net::HTTP::Get.new(uri) get_request.basic_auth(API_KEY, API_SECRET) response = http.request(get_request) response.code # 404, because we haven't created this profile yet. # Now let's create a profile. Use PATCH whenever you want to set some profile information. # It will create a new record if it doesn't already exist. patch_request = Net::HTTP::Patch.new(uri) patch_request.basic_auth(API_KEY, API_SECRET) patch_request.content_type = "application/json" # Set up some arbitrary profile data for Isa profile_attributes = { :name => "Isa", :cats => ["Ofelia", "Mittens", "Spot"], :age => 30, :"lucky numbers" => [1, 48, -100, 13], :birthday => "1983-01-01" } # The data we want to set must be nested under an "attributes" JSON root node patch_request.body = JSON.dump({:attributes => profile_attributes}) response = http.request(patch_request) response.code # 202 # Now Isa should be there response = http.request(get_request) response.code # 200 response.body # {"attributes": {"name": "Isa"...}} # We can update and delete Isa's profile attributes: updated_attributes = { :age => 31, :cats => nil # Use null to delete individual attributes } patch_request.body = JSON.dump({:attributes => updated_attributes}) http.request(patch_request) http.request(get_request) # Isa's age has now been updated and his cats are gone # We're done with Isa delete_request = Net::HTTP::Delete.new(uri) delete_request.basic_auth(API_KEY, API_SECRET) http.request(delete_request) end ``` -------------------------------- ### Get Average Session Length using cURL Source: https://docs.localytics.com/dev/query-api This example demonstrates how to retrieve the average session length from the Localytics API using a cURL command. It requires the API key, secret, and app ID, and specifies the date range for the query. The output is in JSON format. ```curl curl --get 'https://api.localytics.com/v1/query' \ --user 'API_KEY:API_SECRET' \ --data 'app_id=APP_ID' \ --data 'metrics=average_session_length' \ --data-urlencode 'conditions={"day":["between","2015-01-01","2015-01-08"]}' ``` -------------------------------- ### Get User Identifiers (Localytics SDK) Source: https://docs.localytics.com/dev/react-native Returns a Javascript object containing user identifying data, including customer ID, first name, last name, full name, and email. These values are only populated if explicitly set via the SDK. ```javascript var identifiers = localytics.identifiers; // {"customer_id": "3neRKTxbNWYKM4NJ", "first_name": "John", "last_name": "Smith", "full_name": "Sir John Smith, III", "email": "sir.john@smith.com"}; ``` -------------------------------- ### Display LLInboxViewController with Loading Indicator (Swift) Source: https://docs.localytics.com/dev/ios This Swift code shows how to create an instance of `LLInboxViewController`, enable its loading indicator by setting `showsActivityIndicatorView` to `true`, and then push it onto the navigation controller. This provides a direct way to display the inbox with a loading indicator. ```Swift func displayInbox() { let inboxViewController = LLInboxViewController() inboxViewController.showsActivityIndicatorView = true self.navigationController?.pushViewController(inboxViewController, animated: true) } ``` -------------------------------- ### Implement Localytics Analytics Callbacks Source: https://docs.localytics.com/dev/tvOS Registers the Localytics analytics delegate and provides example implementations for various analytics callbacks, including session opening, event tagging, and session closing. These callbacks allow for custom actions based on user sessions and events. ```objectivec - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // ...Localytics initialization code here... [Localytics setAnalyticsDelegate:self]; // ... rest of didFinishLaunchingWithOptions ... return YES; } - (void)localyticsSessionWillOpen:(BOOL)isFirst isUpgrade:(BOOL)isUpgrade isResume:(BOOL)isResume { // ... do something ... } - (void)localyticsSessionDidOpen:(BOOL)isFirst isUpgrade:(BOOL)isUpgrade isResume:(BOOL)isResume { // ... do something ... } - (void)localyticsDidTagEvent:(NSString *) attributes:(NSDictionary *)attributes customerValueIncrease:(NSNumber *)customerValueIncrease { // ... do something ... } - (void)localyticsSessionWillClose { // ... do something ... } ``` ```swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // ...Localytics initialization code here... Localytics.setAnalyticsDelegate(self) // ... rest of didFinishLaunchingWithOptions ... return true } func localyticsSessionWillOpen(_ isFirst: Bool, isUpgrade: Bool, isResume: Bool) { // ... do something ... } func localyticsSessionDidOpen(_ isFirst: Bool, isUpgrade: Bool, isResume: Bool) { // ... do something ... } func localyticsDidTagEvent(_ eventName: String, attributes: [String : String]? = nil, customerValueIncrease: NSNumber?) { // ... do something ... } func localyticsSessionWillClose() { // ... do something ... } ``` -------------------------------- ### Initialize Localytics SDK with Basic Integration Options Source: https://docs.localytics.com/dev/web Initializes the Localytics Web SDK with options for basic web push integration. Requires setting the worker path, worker name, and public key. These parameters are crucial for service worker registration and push notification handling. ```javascript ll('init', 'YOUR_APP_KEY', { workerPath: '/', workerName: 'worker.js', publicKey: 'YOUR_PUBLIC_KEY_AS_PROVIDED_TO_LOCALYTICS_DASHBOARD' }); ``` -------------------------------- ### Setting Numeric Profile Attribute in Localytics Source: https://docs.localytics.com/dev/windows This example demonstrates setting a numeric profile attribute for a user in Localytics, with an option for organization-level scope. It requires the Localytics SDK, attribute name, a numeric value, and a scope constant. This allows for granular user segmentation. ```csharp Localytics.SetProfileAttribute("Age", 45, Profiles.SCOPE_ORG); ``` -------------------------------- ### TagStartedCheckout Source: https://docs.localytics.com/dev/maui Tags a standard event for the start of the checkout process. ```APIDOC ## TagStartedCheckout ### Description A standard event to tag the start of the checkout process (after the action has occurred). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ```