Product Experiences

Product Config is available for CleverTap iOS SDK 3.8.0 and above.

Set Product Config

Integrate Product Config

You have to import the CleverTap Product Config Header.

import CleverTapSDK;
#import <CleverTapSDK/CleverTap+ProductConfig.h>

Grab the Product Config singleton object

var productConfig: CleverTapProductConfig? = CleverTap.sharedInstance()?.productConfig
CleverTapProductConfig *productConfig = [[CleverTap sharedInstance] productConfig];

Set default parameter values

You can set in-app default parameter values in the Product Config object so that your app behaves as intended before values are fetched from CleverTap, and so that default values are available if none are set on the dashboard.
Define a set of parameter names, and default parameter values using a plist file or an NSDictionary object.

plist file

CleverTap.sharedInstance()?.productConfig.setDefaultsFromPlistFileName("ProductConfigDefaults")
[[[CleverTap sharedInstance] productConfig] setDefaultsFromPlistFileName:@"ProductConfigDefaults"];

NSDictionary object

let defaults = NSMutableDictionary()
 defaults.setValue("value", forKey: "key")
 CleverTap.sharedInstance()?.productConfig.setDefaults(defaults as? [String : NSObject])
NSMutableDictionary *defaults = [NSMutableDictionary new];
[defaults setValue:@"value" forKey:@"key"];
[[[CleverTap sharedInstance] productConfig] setDefaults:[defaults mutableCopy]];

Fetch and activate values

To fetch parameter values from CleverTap, call the fetch() method. Any values that you set on the dashboard are fetched and stored in the Product Config object.
To make fetched parameter values available to your app, call the activate() method.

For cases where you want to fetch and activate values in one call, you can use a fetchAndActivate()request to fetch values from CleverTap and make them available to the app:

Fetch

CleverTap.sharedInstance()?.productConfig.fetch()
[[[CleverTap sharedInstance] productConfig] fetch];

By default, the fetch calls are throttled, which is controlled from the CleverTap servers as well as SDK. To know more see the Throttling section.

In some specific cases if you require to call fetch without the default throttling, you can use fetchWithMinimumInterval:

CleverTap.sharedInstance()?.productConfig.fetch(withMinimumInterval: 60*10)
[[[CleverTap sharedInstance] productConfig] fetchWithMinimumInterval:60*10];

Here the interval is used to decide whether we can fetch or not. You can keep the interval as per your requirement, however, you should keep it high to avoid making frequent requests to the backend.

Activate

CleverTap.sharedInstance()?.productConfig.activate()
[[[CleverTap sharedInstance] productConfig] activate];

FetchAndActivate

CleverTap.sharedInstance()?.productConfig.fetchAndActivate()
[[[CleverTap sharedInstance] productConfig] fetchAndActivate];

Throttling

If an app fetches too many times in a short time period, fetch calls are throttled.
Throttling is controlled from the CleverTap servers as well from the SDK. The maximum value of the two will be considered to make the next fetch request. You can set the next fetch interval from the SDK below.

CleverTap.sharedInstance()?.productConfig.setMinimumFetchInterval(60*10)
[[[CleverTap sharedInstance] productConfig] setMinimumFetchInterval:60*10];

Resetting the Product Config

Anytime you want to reset the settings and/or already stored data to start fresh you can do that via the reset method.

CleverTap.sharedInstance()?.productConfig.reset()
[[[CleverTap sharedInstance] productConfig] reset];

Last Fetched Time Stamp

You can always get the timestamp of the configuration fetched last time.

CleverTap.sharedInstance()?.productConfig.getLastFetchTimeStamp()
[[[CleverTap sharedInstance] productConfig] getLastFetchTimeStamp];

Registering the CleverTap Product Config

Check that your class implements the CleverTapProductConfigDelegate and set to the class.

import UIKit
import CleverTapSDK

class ViewController: UIViewController, CleverTapProductConfigDelegate  {

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        CleverTap.sharedInstance()?.productConfig.delegate = self;
    }
}
#import "ViewController.h"
#import <CleverTapSDK/CleverTap.h>
#import <CleverTapSDK/CleverTap+ProductConfig.h>

@interface ViewController () <CleverTapProductConfigDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    ...
    [CleverTap sharedInstance].productConfig.delegate = self;
}
@end

To receive callbacks whenever product config is initialized, fetched, and activated, you can implement the below method defined in CleverTapFeatureFlagsDelegate protocol:

func ctProductConfigInitialized() {
    ...  
    print("Product Config Initialized")
}
    
func ctProductConfigFetched() {
    ...
    print("Product Config Fetched")
}
    
func ctProductConfigActivated() {
    ...
    print("Product Config Activated")
}
- (void)ctProductConfigInitialized {
    ...
    NSLog(@"Product Config Initialized");
}
 
- (void)ctProductConfigFetched {
    ...
    NSLog(@"Product Config Fetched");
}
 
- (void)ctProductConfigActivated {
    ...
    NSLog(@"Product Config Activated");
}

Get parameter values to use in your app

let ctValue = CleverTap.sharedInstance()?.productConfig.get("key")
NSString *stringValue = [[[[CleverTap sharedInstance] productConfig] get:@"key"] stringValue];

BOOL boolValue = [[[[CleverTap sharedInstance] productConfig] get:@"key"] boolValue];

NSNumber *numberValue = [[[[CleverTap sharedInstance] productConfig] get:@"key"] numberValue];

id jsonValue = [[[[CleverTap sharedInstance] productConfig] get:@"key"] jsonValue];

Set Feature Flag

Feature flags let you toggle a feature on and off controlled via CleverTap Backend.

Grab the Feature Flag singleton object

var featureFlags: CleverTapFeatureFlags = CleverTap.sharedInstance()?.featureFlags
CleverTapFeatureFlags *featureFlags = [[CleverTap sharedInstance] featureFlags];

Feature flags are automatically fetched every time a new app session is created. Once the flags are fetched you can get it via the getters.

Register the Delegate

import CleverTapSDK;
#import <CleverTapSDK/CleverTap+FeatureFlags.h>

To use this, make sure your class implements the CleverTapFeatureFlagsDelegate and set to the class.

import UIKit
import CleverTapSDK

class ViewController: UIViewController, CleverTapFeatureFlagsDelegate  {

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        CleverTap.sharedInstance()?.featureFlags.delegate = self;
    }
}
#import "ViewController.h"
#import <CleverTapSDK/CleverTap.h>
#import <CleverTapSDK/CleverTap+FeatureFlags.h>

@interface ViewController () <CleverTapFeatureFlagsDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    ...
    [CleverTap sharedInstance].featureFlags.delegate = self;
}

@end

To receive callbacks whenever feature flags are fetched, you can implement the below method defined in CleverTapFeatureFlagsDelegate protocol.

func ctFeatureFlagsUpdated() {
    ...
    NSLog("CleverTap feature flags updated")
}
- (void)ctFeatureFlagsUpdated {
    ...
    NSLog(@"CleverTap feature flags updated");
}

Getting the Feature Flags

To get the value of a feature simply call get: withDefaultValue: Default value is the value which will be returned in case there are no feature flags with the key.

let featureFlag = CleverTap.sharedInstance()?.featureFlags.get("key", withDefaultValue:false)
BOOL featureFlag = [[[CleverTap sharedInstance] featureFlags] get:@"key" withDefaultValue:true];

Did this page help you?