Suggested readings: App Content Optimizer, Use Cases for App Content Optimizer
The following methods are required to create variables for App Content Optimizer depending on the data type.
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 prioritize efficiency and reliability, you can use these methods to maintain seamless content delivery without requiring a new data request each time.
Get string data
This method allows you to retrieve string-type data.
| Parameter | Type |
|---|---|
| variableName | String |
| defaultValue | String |
| dataType | ContentOptimizerDataType |
Method signature
+(NSString *)getContentStringWithName:(NSString *)name defaultString:(NSString *)defaultString dataType:(ContentOptimizerDataType)dataType;Method examples
The following code snippets show how to use this method in Objective-C and Swift.
[Insider getContentStringWithName:@"variableName" defaultString:@"defaultValue" dataType:ContentOptimizerDataTypeElement];Insider.getContentString(withName: "variableName", defaultString: "defaultValue", dataType: ContentOptimizerDataType.element)Get boolean data
This method allows you to retrieve Boolean data.
| Parameter | Type |
|---|---|
| variableName | String |
| defaultValue | Boolean |
| dataType | ContentOptimizerDataType |
Method signature
+(BOOL)getContentBoolWithName:(NSString *)name defaultBool:(BOOL)defaultBool dataType:(ContentOptimizerDataType)dataType;Method examples
The following code snippets show how to use this method in Objective-C and Swift.
[Insider getContentBoolWithName:@"variableName" defaultBool:true dataType:ContentOptimizerDataTypeElement];Insider.getContentBool(withName: "variableName", defaultBool: true, dataType: ContentOptimizerDataType.element)Get integer data
This method allows you to retrieve integer-type data.
| Parameter | Type |
|---|---|
| variableName | String |
| defaultValue | Integer |
| dataType | ContentOptimizerDataType |
Method signature
+(int)getContentIntWithName:(NSString *)name defaultInt:(int)defaultInt dataType:(ContentOptimizerDataType)dataType;Method examples
The following code snippets show how to use this method in Objective-C and Swift.
[Insider getContentIntWithName:@"variableName" defaultInt:10 dataType:ContentOptimizerDataTypeElement];Insider.getContentInt(withName: "variableName", defaultInt: 10, dataType: 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 rather than relying on cached 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 to maintain a smooth user experience.
Get string data
This method allows you to retrieve string type of data.
| Parameter | Type |
|---|---|
| variableName | String |
| defaultValue | String |
| dataType | ContentOptimizerDataType |
Method signature
+(NSString *)getContentStringWithoutCache:(NSString *)name defaultString:(NSString *)defaultString dataType:(ContentOptimizerDataType)dataType;Method examples
The following code snippets show how to use this method in Objective-C and Swift.
[Insider getContentStringWithoutCache:@"variableName" defaultString:@"defaultValue" dataType:ContentOptimizerDataTypeElement];Insider.getContentStringWithoutCache(withName: "variableName", defaultString: "defaultValue", dataType: ContentOptimizerDataType.element)Get boolean data
This method allows you to retrieve a Boolean type of data.
| Parameter | Type |
|---|---|
| variableName | String |
| defaultValue | Boolean |
| dataType | ContentOptimizerDataType |
Method signature
+(BOOL)getContentBoolWithoutCache:(NSString *)name defaultBool:(BOOL)defaultBool dataType:(ContentOptimizerDataType)dataType;Method examples
The following code snippets show how to use this method in Objective-C and Swift.
[Insider getContentBoolWithoutCache:@"variableName" defaultBool:true dataType:ContentOptimizerDataTypeElement];Insider.getContentBoolWithoutCache(withName: "variableName", defaultBool: true, dataType: ContentOptimizerDataType.element)Get integer data
This method allows you to retrieve integer-type data.
| Parameter | Type |
|---|---|
| variableName | String |
| defaultValue | Integer |
| dataType | ContentOptimizerDataType |
Method signature
+(int)getContentIntWithoutCache:(NSString *)name defaultInt:(int)defaultInt dataType:(ContentOptimizerDataType)dataType;Method examples
The following code snippets show how to use this method in Objective-C and Swift.
[Insider getContentIntWithoutCache:@"variableName" defaultInt:10 dataType:ContentOptimizerDataTypeElement];Insider.getContentIntWithoutCache(withName: "variableName", defaultInt: 10, dataType: ContentOptimizerDataType.element)markContentOptimizerAsSeen
This method reports a seen impression for a Content Optimizer variable the partner has just displayed. After fetching an optimized value with one of the getContent... methods and showing it to the user, the partner calls 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.
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 disabled or GDPR is opted out → 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 → 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:
1. Fetch the value with a getContent... method.
2. Render it in the UI.
3. Call markContentOptimizerAsSeen: with the same variable name.
Method signatures
+ (void)markContentOptimizerAsSeen:(NSString * _Nonnull)variableName;
class func markContentOptimizerAsSeen(_ variableName: String)
Method examples
// 1. Fetch the optimized value
let bannerTitle = Insider.getContentString(
withName: "banner_title",
defaultString: "Welcome!",
dataType: .string
)
// 2. Show it to the user
titleLabel.text = bannerTitle
// 3. Report the impression — fires `cont_opt_seen`
Insider.markContentOptimizerAsSeen("banner_title")
// 1. Fetch the optimized value
NSString *bannerTitle = [Insider getContentStringWithName:@"banner_title"
defaultString:@"Welcome!"
dataType:ContentOptimizerDataTypeString];
// 2. Show it to the user
self.titleLabel.text = bannerTitle;
// 3. Report the impression — fires `cont_opt_seen`
[Insider markContentOptimizerAsSeen:@"banner_title"];