--- title: "Content Optimizer" slug: "android-content-optimizer" description: "This article lists the methods required to create variables for App Content Optimizer depending on the data type." tags: ["android content optimizer", "retrieve data"] updated: 2026-09-04T11:02:58Z published: 2026-09-04T11:02:58Z canonical: "academy.insiderone.com/android-content-optimizer" --- > ## Documentation Index > Fetch the complete documentation index at: https://academy.insiderone.com/llms.txt > Use this file to discover all available pages before exploring further. # Content Optimizer > **Suggested readings:** [App Content Optimizer](https://academy.insiderone.com/docs/content-optimizer-overview), [Use Cases for App Content Optimizer](https://academy.insiderone.com/docs/content-optimizer-use-cases) Content Optimizer lets you define variables (strings, ints, booleans) on the Insider dashboard and pull their optimized values at runtime. It's typically used for A/B Testing copy, prices, banners, or feature flags without shipping a new build. The SDK exposes two parallel families of six methods: one cached and one uncached. | Family | Behavior | | --- | --- | | getContent…WithName(...) | Uses the device-local cache. Returns the last value the SDK fetched; refreshes in the background. | | getContent…WithoutCache(...) | Bypasses the cache and queries the backend. | ## Retrieving Content with Stored Data The Content Optimizer feature provides methods that store the last retrieved data on the device. When using these methods, the SDK retrieves and returns the most recently fetched value, reducing the need for repeated network requests. This approach enhances performance and ensures consistent content availability across sessions. If you prefer to prioritize efficiency and reliability, you can use these methods to maintain seamless content delivery without requiring a fresh data request each time. ### Get string data This method allows you to retrieve a string type of data. To add Content Optimizer variables, you must first [add your device as a test device](https://academy.insiderone.com/docs/adding-a-test-device-on-mobile-app). After adding it as a test device, you need to trigger the Content Optimizer method to display the respective variable in the Content Optimizer variables. | Parameter | Type | | --- | --- | | variableName | String | | defaultValue | String | | dataType | ContentOptimizerDataType | #### Method Signature ```java public String getContentStringWithName(String variableName, String defaultValue, ContentOptimizerDataType dataType) ``` ```custom fun getContentStringWithName( variableName: String, defaultValue: String, dataType: ContentOptimizerDataType ): String ``` #### Method Example ```java Insider.Instance.getContentStringWithName("variableName", "defaultValue", ContentOptimizerDataType.ELEMENT); ``` ```custom val title = Insider.Instance.getContentStringWithName( "home_hero_title", "Welcome", ContentOptimizerDataType.ELEMENT ) ``` --- ### Get boolean data This method allows you to retrieve a boolean type of data. To add Content Optimizer variables, you must first [add your device as a test device.](https://academy.insiderone.com/docs/adding-a-test-device-on-mobile-app) After adding it as a test device, you need to trigger the Content Optimizer method to display the respective variable in the Content Optimizer variables. | Parameter | Type | | --- | --- | | variableName | String | | defaultValue | Boolean | | dataType | ContentOptimizerDataType | #### Method Signature ```java public boolean getContentBoolWithName(String variableName, boolean defaultValue, ContentOptimizerDataType dataType) ``` ```custom fun getContentBoolWithName( variableName: String, defaultValue: Boolean, dataType: ContentOptimizerDataType ): Boolean ``` #### Method Example ```java Insider.Instance.getContentBoolWithName("variableName", true, ContentOptimizerDataType.ELEMENT); ``` ```custom val wishlistEnabled = Insider.Instance.getContentBoolWithName( "feature_wishlist_enabled", true, ContentOptimizerDataType.ELEMENT ) ``` --- ### Get integer data This method allows you to retrieve an integer type of data. To add Content Optimizer variables, you must first [add your device as a test device](https://academy.insiderone.com/docs/adding-a-test-device-on-mobile-app). After adding it as a test device, you need to trigger the Content Optimizer method to display the respective variable in the Content Optimizer variables. | Parameter | Type | | --- | --- | | variableName | String | | defaultValue | Integer | | dataType | ContentOptimizerDataType | #### Method Signature ```java public int getContentIntWithName(String variableName, int defaultValue, ContentOptimizerDataType dataType) ``` ```custom fun getContentIntWithName( variableName: String, defaultValue: Int, dataType: ContentOptimizerDataType ): Int ``` #### Method Example ```java Insider.Instance.getContentIntWithName("variableName", 10, ContentOptimizerDataType.ELEMENT); ``` ```custom val discount = Insider.Instance.getContentIntWithName( "checkout_discount_percent", 10, ContentOptimizerDataType.ELEMENT ) ``` ## Retrieving Content Without Stored Data For use cases that require real-time content updates, alternative methods can be used that always request the latest data from the backend instead of using stored values. These methods ensure that the most up-to-date information is retrieved at the time of request, making them ideal for time-sensitive campaigns or dynamic content updates. By using this approach, you gain full control over content freshness, ensuring that the latest data is always reflected in your applications. If real-time data is unavailable at the time of the request, the specified default value will be returned, ensuring a smooth user experience. ### Get string data This method allows you to retrieve a string type of data. To add Content Optimizer variables, you must first [add your device as a test device](https://academy.insiderone.com/docs/adding-a-test-device-on-mobile-app). After adding it as a test device, you need to trigger the Content Optimizer method to display the respective variable in the Content Optimizer variables. | Parameter | Type | | --- | --- | | variableName | String | | defaultValue | String | | dataType | ContentOptimizerDataType | #### Method Signature ```java public String getContentStringWithoutCache(String variableName, String defaultValue, ContentOptimizerDataType dataType) ``` ```custom fun getContentStringWithoutCache( variableName: String, defaultValue: String, dataType: ContentOptimizerDataType ): String ``` #### Method Example ```java Insider.Instance.getContentStringWithoutCache("variableName", "defaultValue", ContentOptimizerDataType.ELEMENT); ``` ```custom val title = Insider.Instance.getContentStringWithoutCache( "home_hero_title", "Welcome", ContentOptimizerDataType.ELEMENT ) ``` --- ### Get boolean data This method allows you to retrieve a boolean type of data. To add Content Optimizer variables, you must first [add your device as a test device](https://academy.insiderone.com/docs/adding-a-test-device-on-mobile-app). After adding it as a test device, you need to trigger the Content Optimizer method to display the respective variable in the Content Optimizer variables. | Parameter | Type | | --- | --- | | variableName | String | | defaultValue | Boolean | | dataType | ContentOptimizerDataType | #### Method Signature ```java public boolean getContentBoolWithoutCache(String variableName, boolean defaultValue, ContentOptimizerDataType dataType) ``` ```custom fun getContentBoolWithoutCache( variableName: String, defaultValue: Boolean, dataType: ContentOptimizerDataType ): Boolean ``` #### Method Example ```java Insider.Instance.getContentBoolWithoutCache("variableName", true, ContentOptimizerDataType.ELEMENT); ``` ```custom val wishlistEnabled = Insider.Instance.getContentBoolWithoutCache( "feature_wishlist_enabled", true, ContentOptimizerDataType.ELEMENT ) ``` --- ### Get integer data This method allows you to retrieve an integer type of data. To add Content Optimizer variables, you must first [add your device as a test device](https://academy.insiderone.com/docs/adding-a-test-device-on-mobile-app). After adding it as a test device, you need to trigger the Content Optimizer method to display the respective variable in the Content Optimizer variables. | Parameter | Type | | --- | --- | | variableName | String | | defaultValue | Integer | | dataType | ContentOptimizerDataType | #### Method Signature ```java public int getContentIntWithoutCache(String variableName, int defaultValue, ContentOptimizerDataType dataType) ``` ```custom fun getContentIntWithoutCache( variableName: String, defaultValue: Int, dataType: ContentOptimizerDataType ): Int ``` #### Method Example ```java Insider.Instance.getContentIntWithoutCache("variableName", 10, ContentOptimizerDataType.ELEMENT); ``` ```custom val discount = Insider.Instance.getContentIntWithoutCache( "checkout_discount_percent", 10, ContentOptimizerDataType.ELEMENT ) ``` ## markContentOptimizerAsSeen This method reports a seen impression for a Content Optimizer variable that you have just displayed. After fetching an optimized value with one of the getContent… methods and showing it to the user, call this method and the SDK fires a cont_opt_seen event carrying the campaign metadata. This lets Insider attribute impressions to the correct Content Optimizer campaign/variant. The event payload has the following: - variable_name: The name passed in (always present) - content_id: The campaign ID, when available - variant_id: The variant ID, when available > If the variableName is null or empty → no-op. > > If the SDK is **not initialized** or GDPR is **opted out** → no-op. > > If the variable was **never fetched**, or **no campaign** is stored for it → no-op. > > If the variable was fetched via both the session-variables and the cache paths, session-variables wins. > > There is **no deduplication**. Each call fires a new event. E.g., 3 calls fire 3 events. You need to call this method immediately after you've actually shown the optimized value to the user, using the same variable name you passed to the getContent… method: Fetch the value with a getContent… method, render it in the UI, and call markContentOptimizerAsSeen with the same variable name. | Parameter | Type | | --- | --- | | variableName | String | ### Method signature ```java public void markContentOptimizerAsSeen(String variableName) ``` ### Method examples ```java Insider.Instance.markContentOptimizerAsSeen("variableName"); ``` ```java // 1. Fetch the optimized value String bannerTitle = Insider.Instance.getContentStringWithName( "banner_title", "Welcome!", ContentOptimizerDataType.ELEMENT ); // 2. Show it to the user bannerTitleView.setText(bannerTitle); // 3. Report the impression — fires `cont_opt_seen` Insider.Instance.markContentOptimizerAsSeen("banner_title"); ``` ```custom Insider.Instance.markContentOptimizerAsSeen("variableName") ``` ```custom // 1. Fetch the optimized value val bannerTitle = Insider.Instance.getContentStringWithName( "banner_title", "Welcome!", ContentOptimizerDataType.ELEMENT ) // 2. Show it to the user bannerTitleView.text = bannerTitle // 3. Report the impression — fires `cont_opt_seen` Insider.Instance.markContentOptimizerAsSeen("banner_title") ``` ## Related - [Use Cases for App Content Optimizer](/content-optimizer-use-cases.md)