### Example Template Definition Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/CustomCodeTemplates.md Provides a complete example of a template definition, showcasing various argument types including boolean, string, object, action, and file. ```json "Example template": { "type": "template", "arguments": { "boolArg": { "type": "boolean", "value": false }, "stringArg": { "type": "string", "value": "Default" }, "mapArg": { "type": "object", "value": { "int": { "type": "number", "value": 0 }, "string": { "type": "string", "value": "Default" } } }, "actionArg": { "type": "action" }, "fileArg": { "type": "file" } } } ``` -------------------------------- ### Push Install Referrer Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Tracks the install referrer information, which is crucial for attribution analysis. Provide source, medium, and campaign details. ```Dart CleverTapPlugin.pushInstallReferrer("source", "medium", "campaign"); ``` -------------------------------- ### Attributions API Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md APIs for pushing install referrer information. ```APIDOC ## POST /attributions/installReferrer ### Description Pushes install referrer information to the CleverTap SDK. ### Method POST ### Endpoint /attributions/installReferrer ### Parameters #### Request Body - **source** (String) - Required - The source of the install referrer. - **medium** (String) - Required - The medium of the install referrer. - **campaign** (String) - Required - The campaign of the install referrer. ### Request Example ```json { "source": "google", "medium": "cpc", "campaign": "summer_sale" } ``` ### Response #### Success Response (200) - **message** (String) - Confirmation message. #### Response Example ```json { "message": "Install referrer pushed successfully." } ``` ``` -------------------------------- ### Get All Qualified Campaign Details Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Fetches details for all campaigns that the user is qualified for. ```Dart CleverTapPlugin.getAllQualifiedCampaignDetails(); ``` -------------------------------- ### Add CleverTap Flutter SDK to pubspec.yaml Source: https://github.com/clevertap/clevertap-flutter/blob/master/README.md Add the CleverTap Flutter SDK dependency to your project's pubspec.yaml file. Run 'flutter packages get' to install. ```yaml dependencies: clevertap_plugin: 4.1.0 ``` -------------------------------- ### Web Inbox Setup Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Configure the web inbox by adding a hidden button with a specific ID and optionally using the NotificationButton widget. ```html ``` ```dart NotificationButton(child: Icon(Icons.notifications)) ``` -------------------------------- ### Get CleverTap Web SDK Version Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Retrieves the current version of the CleverTap Web SDK. ```Dart CleverTapPlugin.getSDKVersion() ``` -------------------------------- ### Get Last Fetch Timestamp Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Retrieves the timestamp in milliseconds of the last successful product configuration fetch. ```Dart CleverTapPlugin.getLastFetchTimeStampInMillis(); ``` -------------------------------- ### Get Boolean Product Config Value Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Retrieves a boolean value for a given product configuration key. Provide a default value to be returned if the key is not found. ```Dart CleverTapPlugin.getProductConfigBoolean("key"); ``` -------------------------------- ### Get All Inbox Messages Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Asynchronously retrieve a list of all messages from the web inbox. ```dart List messages = await CleverTapPlugin.getAllInboxMessages(); ``` -------------------------------- ### Get All Display Units Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Retrieves all available display units from CleverTap. Ensure the widget is in a stateful context to update the UI. ```Dart void onDisplayUnitsLoaded(List displayUnits) { this.setState(() async { List displayUnits = await CleverTapPlugin.getAllDisplayUnits(); print("Display Units = " + displayUnits.toString()); }); } ``` -------------------------------- ### Import CleverTap Flutter SDK in Dart code Source: https://github.com/clevertap/clevertap-flutter/blob/master/README.md Import the CleverTap Flutter SDK into your Dart files to start using its functionalities. ```dart import 'package:clevertap_plugin/clevertap_plugin.dart'; ``` -------------------------------- ### Initialize and Fetch Product Configuration Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Initializes product configuration and fetches the latest configurations from CleverTap. This should be called during app startup. ```Dart void productConfigInitialized() { print("Product Config Initialized"); this.setState(() async { await CleverTapPlugin.fetch(); }); } ``` -------------------------------- ### Initialization Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Initialize the CleverTap SDK with your account credentials and region. ```APIDOC ## Initialization ### Description Initialize the CleverTap SDK with your account ID, region, target domain, and token. ### Method `CleverTapPlugin.init(String accountID, String region, String targetDomain, String token)` ### Parameters #### Path Parameters - **accountID** (String) - Required - Your CleverTap Account ID. - **region** (String) - Optional - The region of your CleverTap Dashboard (e.g., 'in1', 'us1', 'sg1', 'aps3', 'mec1'). - **targetDomain** (String) - Optional - The domain of the proxy server. - **token** (String) - Optional - Mandatory only when using the remote config feature. Your CleverTap Token. ### Request Example ```Dart CleverTapPlugin.init("CLEVERTAP_ACCOUNT_ID", "CLEVERTAP_REGION", "CLEVERTAP_TARGET_DOMAIN", "CLEVERTAP_TOKEN"); ``` ``` -------------------------------- ### Push Primer Integration Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Information on integrating the Push Primer for notification permissions. ```APIDOC ## Push Primer Integration ### Description Follow the [Push Primer integration doc](PushPrimer.md) for detailed instructions on integrating the Push Primer for notification permissions on Android and iOS. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Fetch and Activate Product Configuration Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Fetches the latest product configurations and immediately activates them. This is a convenient method for ensuring the app uses the newest settings. ```Dart void fetchAndActivate() { CleverTapPlugin.fetchAndActivate(); } ``` -------------------------------- ### Fetch Product Configurations Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Fetches the latest product configurations from CleverTap. Use `fetchWithMinimumIntervalInSeconds` to control the fetch frequency. ```Dart void fetch() { CleverTapPlugin.fetch(); // CleverTapPlugin.fetchWithMinimumIntervalInSeconds(0); } ``` -------------------------------- ### Product Configuration API Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md APIs for managing product configurations, including fetching, activating, and setting defaults. ```APIDOC ## POST /productConfig/fetch ### Description Fetches the latest product configuration from the server. ### Method POST ### Endpoint /productConfig/fetch ### Parameters None ### Request Example None ### Response #### Success Response (200) - **status** (String) - Indicates the status of the fetch operation. #### Response Example ```json { "status": "fetched" } ``` ``` ```APIDOC ## POST /productConfig/activate ### Description Activates the most recently fetched product configuration. ### Method POST ### Endpoint /productConfig/activate ### Parameters None ### Request Example None ### Response #### Success Response (200) - **status** (String) - Indicates the status of the activation. #### Response Example ```json { "status": "activated" } ``` ``` ```APIDOC ## POST /productConfig/fetchAndActivate ### Description Fetches and activates the product configuration in a single step. ### Method POST ### Endpoint /productConfig/fetchAndActivate ### Parameters None ### Request Example None ### Response #### Success Response (200) - **status** (String) - Indicates the status of the fetch and activate operation. #### Response Example ```json { "status": "fetched_and_activated" } ``` ``` ```APIDOC ## POST /productConfig/setMinimumFetchInterval ### Description Sets the minimum interval in seconds between product config fetches. ### Method POST ### Endpoint /productConfig/setMinimumFetchInterval ### Parameters #### Request Body - **interval** (Integer) - Required - The minimum interval in seconds. ### Request Example ```json { "interval": 3600 } ``` ### Response #### Success Response (200) - **message** (String) - Confirmation message. #### Response Example ```json { "message": "Minimum fetch interval set successfully." } ``` ``` ```APIDOC ## GET /productConfig/boolean ### Description Retrieves a boolean value for a given product config key. ### Method GET ### Endpoint /productConfig/boolean ### Parameters #### Query Parameters - **key** (String) - Required - The key for the boolean product configuration. ### Request Example None ### Response #### Success Response (200) - **value** (Boolean) - The boolean value associated with the key. #### Response Example ```json { "value": true } ``` ``` ```APIDOC ## GET /productConfig/lastFetchTimestamp ### Description Retrieves the timestamp in milliseconds of the last product config fetch. ### Method GET ### Endpoint /productConfig/lastFetchTimestamp ### Parameters None ### Request Example None ### Response #### Success Response (200) - **timestamp** (Long) - The timestamp in milliseconds. #### Response Example ```json { "timestamp": 1678886400000 } ``` ``` -------------------------------- ### Get All Unread Inbox Messages Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Asynchronously retrieve a list of all unread messages from the web inbox. ```dart List messages = await CleverTapPlugin.getUnreadInboxMessages(); ``` -------------------------------- ### Get CleverTap ID Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Retrieve the unique CleverTap ID for the current user. This is an asynchronous operation. ```dart CleverTapPlugin.getCleverTapID().then((clevertapId) {}) ``` -------------------------------- ### Initialize CleverTap Plugin Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Initialize the CleverTap plugin with your account ID, region, target domain, and token. The token is mandatory for remote config. ```dart CleverTapPlugin.init("CLEVERTAP_ACCOUNT_ID", "CLEVERTAP_REGION", "CLEVERTAP_TARGET_DOMAIN","CLEVERTAP_TOKEN"); ``` -------------------------------- ### Get CleverTap Account ID Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Retrieve the CleverTap Account ID configured for the plugin. This is an asynchronous operation. ```dart CleverTapPlugin.getAccountID().then((accountId) {}) ``` -------------------------------- ### Add App-Level Dependencies Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-Android.md Include these implementations in your `app/build.gradle` file. Some are mandatory for specific features like App Inbox or optional for media playback. ```groovy implementation 'com.google.firebase:firebase-messaging:23.4.1' implementation 'androidx.core:core:1.3.0' implementation 'androidx.fragment:fragment:1.3.6' //MANDATORY for App Inbox implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.viewpager:viewpager:1.0.0' implementation 'com.google.android.material:material:1.4.0' implementation 'com.github.bumptech.glide:glide:4.12.0' //For CleverTap Android SDK v3.6.4 and above add the following - implementation 'com.android.installreferrer:installreferrer:2.2' //Optional ExoPlayer/AndroidX Media3 Libraries for Audio/Video Inbox Messages. Audio/Video messages will be dropped without these dependencies implementation 'com.google.android.exoplayer:exoplayer:2.19.1' implementation 'com.google.android.exoplayer:exoplayer-hls:2.19.1' implementation 'com.google.android.exoplayer:exoplayer-ui:2.19.1' ``` -------------------------------- ### Get Inbox Message by ID Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Asynchronously retrieve a specific inbox message using its unique message ID. ```dart var messageForId = await CleverTapPlugin.getInboxMessageForId(messageId); ``` -------------------------------- ### Activate Product Configuration Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Activates the most recently fetched product configuration, making its values available for use in the app. ```Dart void activate() { CleverTapPlugin.activate(); } ``` -------------------------------- ### Get Total Unread Inbox Message Count Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Asynchronously retrieve the count of unread messages in the web inbox. ```dart int unread = await CleverTapPlugin.getInboxMessageUnreadCount(); print("Unread count = " + unread.toString()); ``` -------------------------------- ### Configure Application Class in AndroidManifest.xml Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-Android.md If your project does not have an existing Application class, add this entry to your `AndroidManifest.xml` to use CleverTap's Application class. ```xml ``` -------------------------------- ### Get Total Inbox Message Count Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Asynchronously retrieve the total number of messages available in the web inbox. ```dart int total = await CleverTapPlugin.getInboxMessageCount(); print("Total count = " + total.toString()); ``` -------------------------------- ### Import CleverTap Headers (Swift) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-iOS.md Import the CleverTap SDK and plugin headers in your AppDelegate file for Swift projects. ```swift import CleverTapSDK import clevertap_plugin ``` -------------------------------- ### Get All CleverTap Variables Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Variables.md Retrieves all fetched CleverTap variables as a map. This is useful for accessing multiple variable values at once. ```dart this.setState(() async { Map variables = await CleverTapPlugin.getVariables(); print('getVariables: ' + variables.toString()); }); ``` -------------------------------- ### Initialize CleverTap SDK (Swift) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-iOS.md Initialize the CleverTap SDK using the autoIntegrate option and notify the CleverTap Flutter SDK of application launch in Swift. ```swift CleverTap.autoIntegrate() // integrate CleverTap SDK using the autoIntegrate option CleverTapPlugin.sharedInstance()?.applicationDidLaunch(options: launchOptions) ``` -------------------------------- ### Configure Alert Push Primer Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/PushPrimer.md This JSON configuration is used for displaying an alert-style in-app message to request push notification permissions. Set `inAppType` to 'alert'. ```Dart var pushPrimerJSON = { 'inAppType': 'alert', 'titleText': 'Get Notified', 'messageText': 'Enable Notification permission', 'followDeviceOrientation': true, 'positiveBtnText': 'Allow', 'negativeBtnText': 'Cancel', 'fallbackToSettings': true }; CleverTapPlugin.promptPushPrimer(pushPrimerJSON); ``` -------------------------------- ### CleverTap Flutter SDK Project Structure Source: https://github.com/clevertap/clevertap-flutter/blob/master/CLAUDE.md Outlines the directory structure of the clevertap-flutter project, highlighting key files and their purposes. ```text clevertap-flutter/ ├── lib/ # Dart/Flutter public API │ ├── clevertap_plugin.dart # Main entry point, all public methods │ ├── clevertap_plugin_web_wrapper.dart # Web platform implementation │ └── src/ # Internal implementation │ ├── types.dart # Data models (CleverTapInboxMessage, etc.) │ └── typedefs.dart # Callback type definitions │ ├── android/ # Android implementation │ ├── build.gradle # ⚠️ 2 VERSION NUMBERS HERE │ └── src/main/java/com/clevertap/clevertap_plugin/ │ ├── CleverTapPlugin.java # Main plugin class, handles MethodChannel │ ├── DartToNativePlatformCommunicator.kt # Dart→Native calls │ ├── CleverTapEventEmitter.kt # Native→Dart callbacks/events │ ├── CleverTapListenerProxy.kt # Native SDK event listeners │ ├── Constants.java # Method channel names │ ├── EventNameMapper.kt # Maps events to Dart callbacks │ ├── CleverTapTypeUtils.java # Type conversions (Map↔Bundle) │ ├── Utils.java # Utility methods │ ├── CleverTapEvent.kt # Event data models │ ├── ClevertapCustomTemplates.kt # Custom template handling │ ├── CleverTapAppContextHolder.java # Application context holder │ └── CleverTapApplication.java # Application class setup │ ├── ios/ # iOS implementation │ ├── Classes/ │ │ └── CleverTapPlugin.m # Main plugin, handles MethodChannel │ └── clevertap_plugin.podspec # ⚠️ iOS SDK VERSION HERE │ ├── example/ # Example Flutter app for testing ├── doc/ # Integration guides │ ├── Usage.md # Complete API documentation │ ├── Integrate-Android.md # Android setup instructions │ └── Integrate-iOS.md # iOS setup instructions │ ├── test/ # Unit tests ├── pubspec.yaml # ⚠️ VERSION NUMBER HERE ├── CHANGELOG.md # ⚠️ ADD ENTRIES AT TOP └── README.md # ⚠️ VERSION NUMBER HERE ``` -------------------------------- ### Get a Specific CleverTap Variable Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Variables.md Retrieves the value of a single, specific CleverTap variable by its key. Useful for accessing individual configuration values. ```dart this.setState(() async { var variable = await CleverTapPlugin.getVariable('variable_name'); print('variable value for key \'flutter_var_string\': ' + variable.toString()); }); ``` -------------------------------- ### Apply Google Services Plugin Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-Android.md Apply the `com.google.gms.google-services` plugin at the end of your `app/build.gradle` file. Skip this if you are not using FCM. ```groovy apply plugin: 'com.google.gms.google-services' //skip if not using FCM ``` -------------------------------- ### Get Push Notification Permission Status Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/PushPrimer.md Retrieves the current status of push notification permissions. Handles nullability and checks if permission is enabled. ```Dart bool? isPushPermissionEnabled = await CleverTapPlugin.getPushNotificationPermissionStatus(); if (isPushPermissionEnabled == null) return; if (!isPushPermissionEnabled) { // call Push Primer here. } else { print("Push Permission is already enabled."); } ``` -------------------------------- ### Migrate ExoPlayer to AndroidX Media3 Dependencies Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-Android.md Optional: Replace deprecated ExoPlayer libraries with AndroidX Media3 for compatibility with CleverTap Flutter SDK v2.5.0+. ```groovy androidx.media3:media3-exoplayer:1.1.1 ``` ```groovy androidx.media3:media3-exoplayer-hls:1.1.1 ``` ```groovy androidx.media3:media3-ui:1.1.1 ``` -------------------------------- ### Get Feature Flag Value Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Retrieves the boolean value of a feature flag. Provide a default value to be used if the flag is not found or an error occurs. ```Dart void featureFlagsUpdated() { this.setState(() async { bool booleanVar = await CleverTapPlugin.getFeatureFlag("BoolKey", false); }); } ``` -------------------------------- ### Handle Push Permission Response Callback Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/PushPrimer.md Sets up a handler to receive callbacks regarding the user's response to push notification permission requests. The callback provides a boolean indicating if the permission was accepted. ```Dart _clevertapPlugin.setCleverTapPushPermissionResponseReceivedHandler(pushPermissionResponseReceived); void pushPermissionResponseReceived(bool accepted) { print("Push Permission response called ---> accepted = " + (accepted ? "true" : "false")); } ``` -------------------------------- ### Handle One-Time Variables Changed Callback in CleverTap Flutter Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Variables.md This callback is invoked only once when variables are initialized or changed with a new server value. It triggers on app start or when added if server values are already received. ```Dart CleverTapPlugin.onOneTimeVariablesChanged((variables) { print("onOneTimeVariablesChanged: " + variables.toString()); }); ``` -------------------------------- ### Initialize CleverTap SDK (Objective-C) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-iOS.md Initialize the CleverTap SDK using the autoIntegrate option and notify the CleverTap Flutter SDK of application launch in Objective-C. ```objective-c [CleverTap autoIntegrate]; // integrate CleverTap SDK using the autoIntegrate option [[CleverTapPlugin sharedInstance] applicationDidLaunchWithOptions:launchOptions]; ``` -------------------------------- ### Configure Half-Interstitial Push Primer Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/PushPrimer.md Use this JSON configuration to display a half-interstitial in-app message for requesting push notification permissions. Ensure the `inAppType` is set to 'half-interstitial'. ```Dart var pushPrimerJSON = { 'inAppType': 'half-interstitial', 'titleText': 'Get Notified', 'messageText': 'Please enable notifications on your device to use Push Notifications.', 'followDeviceOrientation': false, 'positiveBtnText': 'Allow', 'negativeBtnText': 'Cancel', 'fallbackToSettings': true, 'backgroundColor': '#FFFFFF', 'btnBorderColor': '#000000', 'titleTextColor': '#000000', 'messageTextColor': '#000000', 'btnTextColor': '#000000', 'btnBackgroundColor': '#FFFFFF', 'btnBorderRadius': '4', 'imageUrl': 'https://icons.iconarchive.com/icons/treetog/junior/64/camera-icon.png', 'altText': 'Alternate Image' }; CleverTapPlugin.promptPushPrimer(pushPrimerJSON); ``` -------------------------------- ### Import CleverTap Headers (Objective-C) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-iOS.md Import the CleverTap SDK and plugin headers in your AppDelegate file for Objective-C projects. ```objective-c #import "CleverTap.h" #import "CleverTapPlugin.h" ``` -------------------------------- ### Create User Profile on Login Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Create or update a user profile when a user logs in. This is useful for associating actions with a logged-in identity. ```dart var stuff = ["bags", "shoes"]; var profile = { 'Name': 'Captain America', 'Identity': '100', 'Email': 'captain@america.com', 'Phone': '+14155551234', 'stuff': stuff }; CleverTapPlugin.onUserLogin(profile); ``` -------------------------------- ### Debugging Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Configure debug level for troubleshooting. ```APIDOC ## Debugging ### Set Debug Level #### Description Sets the debug level for the CleverTap SDK to control the verbosity of logs. #### Method `CleverTapPlugin.setDebugLevel(int level)` #### Parameters - **level** (int) - Required - The debug level (e.g., 3 for verbose logging). #### Request Example ```Dart CleverTapPlugin.setDebugLevel(3); ``` ``` -------------------------------- ### Web Native Display Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Handle custom key-value data changes for web native displays. ```APIDOC ## Web Native Display ### Custom KV Pair #### Description Adds a listener to receive custom key-value data changes for web native displays. #### Method `CleverTapPlugin.addKVDataChangeListener(Function(dynamic obj) callback)` #### Parameters - **callback** (Function(dynamic obj)) - Required - A callback function that receives the custom key-value data object. #### Request Example ```Dart CleverTapPlugin.addKVDataChangeListener((obj) { print(obj); }); ``` ``` -------------------------------- ### Initialize App Inbox Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Initializes the App Inbox feature. This should be called before attempting to show or interact with the inbox. ```Dart CleverTapPlugin.initializeInbox(); ``` -------------------------------- ### CleverTap Flutter SDK Architecture Diagram Source: https://github.com/clevertap/clevertap-flutter/blob/master/CLAUDE.md Illustrates the layered architecture of the CleverTap Flutter SDK, showing the interaction between the Flutter/Dart layer, platform channels, and native SDKs. ```text Flutter/Dart Layer (lib/) ↕ Platform Channels (MethodChannel) ↕ Native Android Layer (android/src/) ←→ CleverTap Android SDK (via Gradle dependency) Native iOS Layer (ios/Classes/) ←→ CleverTap iOS SDK (via CocoaPods) Native Web Layer (lib/) ←→ CleverTap Web SDK (via JS interop) ``` -------------------------------- ### Configure CleverTap Account ID and Token Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-Android.md Add your CleverTap Account ID and Token within the `` tags in your `AndroidManifest.xml`. ```xml ``` -------------------------------- ### Set Minimum Fetch Interval for Product Config Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Sets the minimum time interval in seconds between product configuration fetches. This helps manage API call frequency. ```Dart CleverTapPlugin.setMinimumFetchIntervalInSeconds(interval); ``` -------------------------------- ### Include CleverTap JavaScript Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Add this script to your index.html file to include the CleverTap JavaScript library. ```html ``` -------------------------------- ### Register Custom Templates in iOS Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/CustomCodeTemplates.md Call `[CleverTapPluginCustomTemplates registerCustomTemplates]` in your `AppDelegate.didFinishLaunchingWithOptions` before `[CleverTap autoIntegrate]`. ```objc @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [CleverTapPluginCustomTemplates registerCustomTemplates:@"templates", nil]; [GeneratedPluginRegistrant registerWithRegistry:self]; [[CleverTapPlugin sharedInstance] applicationDidLaunchWithOptions:launchOptions]; [CleverTap autoIntegrate]; // integrate CleverTap SDK using the autoIntegrate option return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end ``` -------------------------------- ### User Profiles Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Manage user profiles by setting, updating, and removing profile information. ```APIDOC ## User Profiles ### Update User Profile (Push Profile) #### Description Updates the user profile with the provided key-value pairs. #### Method `CleverTapPlugin.profileSet(Map profileData)` #### Parameters - **profileData** (Map) - Required - A map containing user profile fields and their values. The 'dob' key requires a specific date format. #### Request Example ```Dart var stuff = ["bags", "shoes"]; var dob = '2012-04-22'; var profile = { 'Name': 'John Wick', 'Identity': '100', 'dob': CleverTapPlugin.getCleverTapDate(DateTime.parse(dob)), 'Email': 'john@gmail.com', 'Phone': '+14155551234', 'stuff': stuff }; CleverTapPlugin.profileSet(profile); ``` ### Set Multi Values For Key #### Description Sets multiple values for a given key in the user profile. #### Method `CleverTapPlugin.profileSetMultiValues(String key, List values)` #### Parameters - **key** (String) - Required - The key for which to set multi-values. - **values** (List) - Required - A list of values to set for the key. #### Request Example ```Dart var values = ["value1", "value2"]; CleverTapPlugin.profileSetMultiValues("props", values); ``` ### Remove Multi Value For Key #### Description Removes specific values from a multi-value key in the user profile. #### Method `CleverTapPlugin.profileRemoveMultiValues(String key, List values)` #### Parameters - **key** (String) - Required - The key from which to remove multi-values. - **values** (List) - Required - A list of values to remove. #### Request Example ```Dart var values = ["value1", "value2"]; CleverTapPlugin.profileRemoveMultiValues("props", values); ``` ### Add Multi Value For Key #### Description Adds multiple values to an existing multi-value key in the user profile. #### Method `CleverTapPlugin.profileAddMultiValues(String key, List values)` #### Parameters - **key** (String) - Required - The key to which to add multi-values. - **values** (List) - Required - A list of values to add. #### Request Example ```Dart var values = ["value1", "value2"]; CleverTapPlugin.profileAddMultiValues("props", values); ``` ### Increment Value For Key #### Description Increments the value of a specified key in the user profile. #### Method `CleverTapPlugin.profileIncrementValue(String key, num value)` #### Parameters - **key** (String) - Required - The key whose value needs to be incremented. - **value** (num) - Required - The amount to increment the value by. #### Request Example ```Dart CleverTapPlugin.profileIncrementValue("score", value); ``` ### Decrement Value For Key #### Description Decrements the value of a specified key in the user profile. #### Method `CleverTapPlugin.profileDecrementValue(String key, num value)` #### Parameters - **key** (String) - Required - The key whose value needs to be decremented. - **value** (num) - Required - The amount to decrement the value by. #### Request Example ```Dart CleverTapPlugin.profileDecrementValue("score", value); ``` ### Create a User profile when user logs in (On User Login) #### Description Creates or updates a user profile when a user logs in. #### Method `CleverTapPlugin.onUserLogin(Map profileData)` #### Parameters - **profileData** (Map) - Required - A map containing user profile fields and their values. #### Request Example ```Dart var stuff = ["bags", "shoes"]; var profile = { 'Name': 'Captain America', 'Identity': '100', 'Email': 'captain@america.com', 'Phone': '+14155551234', 'stuff': stuff }; CleverTapPlugin.onUserLogin(profile); ``` ### Get CleverTap Reference ID #### Description Retrieves the CleverTap Reference ID for the current user. #### Method `Future getCleverTapID()` #### Response Example ```Dart CleverTapPlugin.getCleverTapID().then((clevertapId) { /* Use clevertapId */ }) ``` ### Get CleverTap Account ID #### Description Retrieves the CleverTap Account ID. #### Method `Future getAccountID()` #### Response Example ```Dart CleverTapPlugin.getAccountID().then((accountId) { /* Use accountId */ }) ``` ### Set Location to User Profile #### Description Sets the user's location based on latitude and longitude. #### Method `CleverTapPlugin.setLocation(double latitude, double longitude)` #### Parameters - **latitude** (double) - Required - The latitude of the user's location. - **longitude** (double) - Required - The longitude of the user's location. #### Request Example ```Dart var lat = 19.07; var long = 72.87; CleverTapPlugin.setLocation(lat, long); ``` ``` -------------------------------- ### Fetch Variables Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Variables.md Initiates a request to fetch variables from the server. The method returns a boolean indicating the success of the fetch operation. ```APIDOC ## Fetch Variables ### Description Initiates a request to fetch variables from the server. The method returns a boolean indicating the success of the fetch operation. ### Method `fetchVariables` ### Endpoint N/A (Method call) ### Response #### Success Response (Boolean) - **success** (bool) - True if variables were fetched successfully, false otherwise. ### Request Example ```dart this.setState(() async { bool? success = await CleverTapPlugin.fetchVariables(); print("fetchVariables result: " + success.toString()); }); ``` ``` -------------------------------- ### Show App Inbox with Custom Styling Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Displays the App Inbox with custom styling options for the navigation bar and empty state. ```Dart var styleConfig = { 'noMessageTextColor': '#ff6600', 'noMessageText': 'No message(s) to show.', 'navBarTitle': 'App Inbox' }; CleverTapPlugin.showInbox(styleConfig); ``` -------------------------------- ### Hierarchical Arguments Definition (Dot Notation) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/CustomCodeTemplates.md Shows an alternative way to define hierarchical arguments using dot notation in argument names. This achieves the same grouping as the 'object' type. ```json "arguments": { "map.a": { "type": "number", "value": 5 }, "map.b": { "type": "number", "value": 6 } } ``` -------------------------------- ### Enable Web Push Notifications Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Call this method to enable web push notifications. Ensure Clevertap's service worker is added to your web folder. ```Dart var pushData = { 'titleText': 'Would you like to receive Push Notifications?', 'bodyText': 'We promise to only send you relevant content and give you updates on your transactions', 'okButtonText': 'Ok', 'rejectButtonText': 'Cancel', 'okButtonColor': '#F28046', 'askAgainTimeInSeconds': 5, 'serviceWorkerPath': '/firebase-messaging-sw.js' }; CleverTapPlugin.enableWebPush(pushData); ``` -------------------------------- ### Display Units API Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md APIs for managing and tracking display units within the CleverTap SDK. ```APIDOC ## GET /displayUnits ### Description Retrieves all available display units. ### Method GET ### Endpoint /displayUnits ### Parameters None ### Request Example None ### Response #### Success Response (200) - **displayUnits** (List) - A list of display units. #### Response Example ```json { "displayUnits": [ { "id": "unit1", "content": "..." }, { "id": "unit2", "content": "..." } ] } ``` ``` ```APIDOC ## POST /displayUnitViewed ### Description Tracks a display unit view event. ### Method POST ### Endpoint /displayUnitViewed ### Parameters #### Request Body - **unitId** (String) - Required - The ID of the display unit viewed. ### Request Example ```json { "unitId": "unit1" } ``` ### Response #### Success Response (200) - **message** (String) - Confirmation message. #### Response Example ```json { "message": "Display unit viewed event tracked successfully." } ``` ``` ```APIDOC ## POST /displayUnitClicked ### Description Tracks a display unit click event. ### Method POST ### Endpoint /displayUnitClicked ### Parameters #### Request Body - **unitId** (String) - Required - The ID of the display unit clicked. ### Request Example ```json { "unitId": "unit1" } ``` ### Response #### Success Response (200) - **message** (String) - Confirmation message. #### Response Example ```json { "message": "Display unit clicked event tracked successfully." } ``` ``` -------------------------------- ### Variable Change Callbacks Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Variables.md Provides callbacks to receive feedback on variable changes and fetch statuses. These include `onVariablesChanged`, `onOneTimeVariablesChanged`, `onValueChanged`, `onVariablesChangedAndNoDownloadsPending`, `onceVariablesChangedAndNoDownloadsPending`, and `onFileValueChanged`. ```APIDOC ## Variable Change Callbacks ### Description Provides callbacks to receive feedback on variable changes and fetch statuses. ### Callbacks #### `onVariablesChanged` Invoked when variables are initialized with values fetched from the server. It is called each time new values are fetched. ```dart CleverTapPlugin.onVariablesChanged((variables) { print("onVariablesChanged: " + variables.toString()); }); ``` #### `onOneTimeVariablesChanged` Invoked once when variables are initialized with a value or changed with a new server value. Callback is triggered only once on app start, or when added if server values are already received. ```dart CleverTapPlugin.onOneTimeVariablesChanged((variables) { print("onOneTimeVariablesChanged: " + variables.toString()); }); ``` #### `onValueChanged` Invoked when the value of a specific variable changes. You must provide the name of the variable whose value needs to be observed. ```dart CleverTapPlugin.onValueChanged('variable_name', (variable) { print("onValueChanged: " + variable.toString()); }); ``` #### `onVariablesChangedAndNoDownloadsPending` Invoked when variable values are changed and the files associated with them are downloaded and ready to be used. Callback is triggered each time new values are fetched and downloaded. ```dart CleverTapPlugin.onVariablesChangedAndNoDownloadsPending((variables) => { print('onVariablesChangedAndNoDownloadsPending', variables); }); ``` #### `onceVariablesChangedAndNoDownloadsPending` Invoked only once when variable values are changed and the files associated with them are downloaded and ready to be used. Callback is triggered only once for when new values are fetched and downloaded. ```dart CleverTapPlugin.onceVariablesChangedAndNoDownloadsPending((variables) => { print('onceVariablesChangedAndNoDownloadsPending', variables); }); ``` #### `onFileValueChanged` Registered per file variable. It is called when the file associated with the file variable is downloaded and ready to be used. ```dart CleverTapPlugin.onFileValueChanged('fileVariable', (variable) => { print('onFileValueChanged: ', variable); }); ``` ``` -------------------------------- ### Set Multi Values for User Profile Key Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Set multiple values for a specific key in the user's profile. ```dart var values = ["value1", "value2"]; CleverTapPlugin.profileSetMultiValues("props", values); ``` -------------------------------- ### Hierarchical Arguments Definition (Object) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/CustomCodeTemplates.md Demonstrates defining hierarchical arguments using the 'object' type. This structure groups nested arguments under a parent key. ```json "arguments": { "map": { "type": "object", "value": { "a": { "type": "number", "value": 5 }, "b": { "type": "number", "value": 6 } } } } ``` -------------------------------- ### Update User Profile Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Set or update a user's profile with various attributes. Ensure the 'dob' key is formatted as 'yyyy-MM-dd' using CleverTapPlugin.getCleverTapDate. ```dart var stuff = ["bags", "shoes"]; var dob = '2012-04-22'; var profile = { 'Name': 'John Wick', 'Identity': '100', // Key always has to be "dob" and format should always be yyyy-MM-dd 'dob': CleverTapPlugin.getCleverTapDate(DateTime.parse(dob)), 'Email': 'john@gmail.com', 'Phone': '+14155551234', 'stuff': stuff }; CleverTapPlugin.profileSet(profile); ``` -------------------------------- ### Register Custom Templates in Android Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/CustomCodeTemplates.md Call `CleverTapCustomTemplates.registerCustomTemplates` in your `Application.onCreate` method. Ensure this is called before `super.onCreate()` if extending `CleverTapApplication`. ```java public class MainApplication extends CleverTapApplication { @Override public void onCreate() { ActivityLifecycleCallback.register(this); CleverTapCustomTemplates.registerCustomTemplates(this, "templates.json"); super.onCreate(); } } ``` -------------------------------- ### Define File Variables Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Variables.md Supports defining file variables from version 3.0.0 onwards. This allows for the use of file types such as images (jpg, jpeg, png, gif), text files, and PDFs as variables. ```APIDOC ## Define File Variables ### Description Supports defining file variables from version 3.0.0 onwards. This allows for the use of file types such as images (jpg, jpeg, png, gif), text files, and PDFs as variables. ### Method `defineFileVariable` ### Parameters #### Query Parameters - **variableName** (String) - Required - The name of the file variable to define. ### Request Example ```dart CleverTapPlugin.defineFileVariable("fileVariable"); ``` ``` -------------------------------- ### Configure iOS Custom Proxy Domain Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Configures custom proxy domains for event and push impression handling in iOS using the CleverTap SDK. This involves setting keys in Info.plist and calling autoIntegrate. ```swift CleverTap.autoIntegrate() ``` -------------------------------- ### Add Required Permissions for CleverTap SDK Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-Android.md These permissions are necessary for the CleverTap SDK to send events, user profile information, and to attempt network calls. ```xml ``` -------------------------------- ### Enable App Personalization Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Enables the personalization features within the CleverTap SDK. This should be called before other personalization-related events. ```Dart CleverTapPlugin.enablePersonalization(); ``` -------------------------------- ### Prompt Notification Permission Dialog Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/PushPrimer.md Directly prompts the native notification permission dialog. Set `fallbackToSettings` to true to redirect to app settings if permission is denied. ```Dart var fallbackToSettings = false; CleverTapPlugin.promptForPushNotification(fallbackToSettings); ``` -------------------------------- ### Create Notification in Flutter Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Create a notification using the `CleverTapPlugin.createNotification` method, passing a data map. ```Dart CleverTapPlugin.createNotification(data); ``` -------------------------------- ### Configure PII Encryption (Android) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Configures the encryption level for PII data in the Android `AndroidManifest.xml`. Value '1' means Medium encryption, '0' means None. ```XML ``` -------------------------------- ### User Events Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Track user interactions and events within the application. ```APIDOC ## User Events ### Record an event #### Description Records a custom event with optional event data. #### Method `CleverTapPlugin.recordEvent(String eventName, Map eventData)` #### Parameters - **eventName** (String) - Required - The name of the event to record. - **eventData** (Map) - Optional - A map containing key-value pairs of event data. #### Request Example ```Dart var eventData = { 'first': 'partridge', 'second': 'turtledoves' }; CleverTapPlugin.recordEvent("Flutter Event", eventData); ``` ### Record Charged event #### Description Records a charged event, typically used for purchase tracking, including charge details and items. #### Method `CleverTapPlugin.recordChargedEvent(Map chargeDetails, List> items)` #### Parameters - **chargeDetails** (Map) - Required - A map containing details about the charge (e.g., 'total', 'payment'). - **items** (List>) - Required - A list of maps, where each map represents an item purchased. #### Request Example ```Dart var item1 = { 'name': 'thing1', 'amount': '100' }; var item2 = { 'name': 'thing2', 'amount': '100' }; var items = [item1, item2]; var chargeDetails = { 'total': '200', 'payment': 'cash' }; CleverTapPlugin.recordChargedEvent(chargeDetails, items); ``` ``` -------------------------------- ### Update User Profile (Push Profile) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Use this method to update a user's profile with various attributes. Ensure the 'DOB' key is in 'dd-MM-yyyy' format. ```Dart var stuff = ["bags", "shoes"]; var profile = { 'Name': 'John Wick', 'Identity': '100', 'DOB': '22-04-2000', //Key always has to be "DOB" and format should always be dd-MM-yyyy 'Email': 'john@gmail.com', 'Phone': '14155551234', 'props': 'property1', 'stuff': stuff }; CleverTapPlugin.profileSet(profile); ``` -------------------------------- ### Set User Opt-Out Status Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Use this to manage user consent for data collection. Set to true to opt out, false to opt in. ```Dart CleverTapPlugin.setOptOut(false); // Will opt in the user to send data to CleverTap ``` ```Dart CleverTapPlugin.setOptOut(true); // Will opt out the user to send data to CleverTap ``` -------------------------------- ### App Personalization API Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md APIs for enabling and disabling app personalization features. ```APIDOC ## POST /personalization/enable ### Description Enables app personalization. ### Method POST ### Endpoint /personalization/enable ### Parameters None ### Request Example None ### Response #### Success Response (200) - **message** (String) - Confirmation message. #### Response Example ```json { "message": "Personalization enabled successfully." } ``` ``` ```APIDOC ## POST /personalization/disable ### Description Disables app personalization. ### Method POST ### Endpoint /personalization/disable ### Parameters None ### Request Example None ### Response #### Success Response (200) - **message** (String) - Confirmation message. #### Response Example ```json { "message": "Personalization disabled successfully." } ``` ``` -------------------------------- ### Configure PII Encryption (iOS) Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage.md Configures the encryption level for PII data in the iOS `info.plist`. The key is `CleverTapEncryptionLevel`, where '1' signifies Medium and '0' signifies None. ```Plist CleverTapEncryptionLevel 1 ``` -------------------------------- ### Sync CleverTap Variables in Debug Mode Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Variables.md Sync variables to the CleverTap server. Requires the app to be in DEBUG mode and a user profile marked as a test profile in the CleverTap dashboard. Syncing may fail if another user has an existing draft. ```dart CleverTapPlugin.syncVariables(); ``` -------------------------------- ### Add Project-Level Dependencies Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Integrate-Android.md Add these dependencies to your `project/build.gradle` file. The Google services dependency is mandatory for Firebase Messaging. ```groovy dependencies { classpath 'com.android.tools.build:gradle:8.3.0' classpath 'com.google.gms:google-services:4.4.1' //<--- Mandatory for using Firebase Messaging, skip if not using FCM } ``` -------------------------------- ### Add Multi Value for User Profile Key Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Add a new value to a multi-valued key in the user's profile. ```dart var values = ["value1", "value2"]; CleverTapPlugin.profileAddMultiValues("props", values); ``` -------------------------------- ### Enable/Disable Local Storage Encryption Source: https://github.com/clevertap/clevertap-flutter/blob/master/doc/Usage-Web.md Toggles the encryption of local storage data. Pass false to disable, true to enable. ```Dart // Enable/Disable local storage encryption CleverTapPlugin.enableLocalStorageEncryption(false); ```