### Install iOS Pods Source: https://developer.clevertap.com/docs/clevertap-rudderstack-react-native-integration Navigate to your iOS project directory and install all pod files using the `pod install` command. ```shell pod install ``` -------------------------------- ### Push Install Referrer Source: https://developer.clevertap.com/docs/cordova-advance-features Track install sources for marketing attribution by pushing referrer details. ```javascript CleverTap.pushInstallReferrer("source", "medium", "campaign") ``` -------------------------------- ### Push Install Referrer Source: https://developer.clevertap.com/docs/cordova-advance-features Tracks install sources for marketing attribution by pushing referrer information. ```APIDOC ## Push Install Referrer ### Description Tracks install sources for marketing attribution by pushing referrer information. ### Method CleverTap.pushInstallReferrer(source, medium, campaign) ### Parameters #### Path Parameters - **source** (string) - Required - The source of the install. - **medium** (string) - Required - The medium of the install. - **campaign** (string) - Required - The campaign of the install. ### Code Example ```javascript CleverTap.pushInstallReferrer("source", "medium", "campaign") ``` ``` -------------------------------- ### Get User Profiles API Python Request Source: https://developer.clevertap.com/docs/get-user-profiles-api Example Python code using the 'requests' library to send a POST request to the Get User Profiles API. Ensure you have the library installed. ```python # Recommended python version 2.7 import requests headers = { 'X-CleverTap-Account-Id': 'ACCOUNT_ID', 'X-CleverTap-Passcode': 'PASSCODE', 'Content-Type': 'application/json', } params = ( ('batch_size', '50'), ) data = '{"event_name":"App Launched","from":20171201,"to":20171225}' response = requests.post('https://in1.api.clevertap.com/1/profiles.json', headers=headers, params=params, data=data) ``` -------------------------------- ### Product Config Callback Methods (Swift) Source: https://developer.clevertap.com/docs/product-experiences-ios Implement these methods to handle product config initialization, fetching, and activation events. ```swift func ctProductConfigInitialized() { ... print("Product Config Initialized") } func ctProductConfigFetched() { ... print("Product Config Fetched") } func ctProductConfigActivated() { ... print("Product Config Activated") } ``` -------------------------------- ### Get User Profiles API Node.js Request Source: https://developer.clevertap.com/docs/get-user-profiles-api Example Node.js code using the 'request' module to send a POST request to the Get User Profiles API. Ensure the 'request' module is installed. ```node var request = require('request'); var headers = { 'X-CleverTap-Account-Id': 'ACCOUNT_ID', 'X-CleverTap-Passcode': 'PASSCODE', 'Content-Type': 'application/json' }; var dataString = '{"event_name":"App Launched","from":20171201,"to":20171225}'; var options = { url: 'https://in1.api.clevertap.com/1/profiles.json?batch_size=50', method: 'POST', headers: headers, body: dataString }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } } request(options, callback); ``` -------------------------------- ### Product Config Callback Methods (Objective-C) Source: https://developer.clevertap.com/docs/product-experiences-ios Implement these methods to handle product config initialization, fetching, and activation events. ```objectivec - (void)ctProductConfigInitialized { ... NSLog(@"Product Config Initialized"); } - (void)ctProductConfigFetched { ... NSLog(@"Product Config Fetched"); } - (void)ctProductConfigActivated { ... NSLog(@"Product Config Activated"); } ``` -------------------------------- ### Start CleverTap Instance with Configuration Source: https://developer.clevertap.com/docs/ios-custom-proxy-domain Create and start a CleverTap instance using a pre-configured `CleverTapInstanceConfig` object. ```swift let cleverTapProxyInstance = CleverTap.instance(with: ctConfig) ``` -------------------------------- ### Get Campaigns API Payload Example Source: https://developer.clevertap.com/docs/get-campaigns-api This JSON payload specifies the start and end dates for retrieving campaigns. Ensure the dates are in YYYYMMDD format. ```json { "from": 20160101, "to": 20160101 } ``` -------------------------------- ### Get Campaigns API Request Example (PHP) Source: https://developer.clevertap.com/docs/get-campaigns-api This PHP script demonstrates how to call the Get Campaigns API using the Requests library. Ensure you have the library installed and provide the correct account ID, passcode, and date range. ```php 'ACCOUNT_ID', 'X-CleverTap-Passcode' => 'PASSCODE', 'Content-Type' => 'application/json' ); $data = json_encode(array( "from" => 20160101, "to" => 20160101 )); $response = Requests::post( 'https://in1.api.clevertap.com/1/targets/list.json', $headers, $data ); echo $response->body; ?> ``` -------------------------------- ### Set Up Callbacks Source: https://developer.clevertap.com/docs/react-native-remote-config Provides feedback through multiple callbacks for variable changes. ```APIDOC # Set Up Callbacks CleverTap React Native SDK provides feedback through multiple callbacks. You can select only the required callbacks. They are as follows: * [All Variables Callbacks](#all-variables-callbacks) * [Individual Variable Callback](#individual-variable-callback) * [All File Variables Callback](#all-file-variables-callback) * [File Variables Individual Callback](#file-variables-individual-callback) ## All Variables Callbacks ### `onVariablesChanged` This callback is invoked after the variables are initialized with values fetched from the server. It is called each time new values are fetched. ```javascript CleverTap.onVariablesChanged((variables) => { console.log('onVariablesChanged: ', variables); }); ``` ### `onceVariablesChanged` This callback is invoked after the variables are initialized with values fetched from the server. It is called only once. ```javascript CleverTap.onceVariablesChanged((variables) => { console.log('onceVariablesChanged: ', variables); }); ``` ## Individual Variable Callback ### `onValueChanged` This callback is invoked after the variable's value changes. To monitor its value, you must provide the variable's name. ```javascript CleverTap.onValueChanged('reactnative_var_string', (variable) => { console.log('onValueChanged: ', variable); }); ``` ## All File Variables Callback ### `onVariablesChangedAndNoDownloadsPending` This callback is called when no files need to be downloaded or all downloads have been completed. It is called each time new values are fetched and downloads are completed. ```javascript CleverTap.onVariablesChangedAndNoDownloadsPending('fileVariable', (fileVariable) => { console.log('onVariablesChangedAndNoDownloadsPending: ', fileVariable); }); ``` ### `onceVariablesChangedAndNoDownloadsPending` This callback is called only once when no files need to be downloaded, or all downloads have been completed. ```javascript CleverTap.onceVariablesChangedAndNoDownloadsPending('fileVariable', (fileVariable) => { console.log('onceVariablesChangedAndNoDownloadsPending: ', fileVariable); }); ``` ## File Variables Individual Callback ### `onFileValueChanged` This callback is called when the file variable's value is downloaded and ready. It is available only for File variables. ```javascript CleverTap.onFileValueChanged('fileVariable', (fileVariable) => { console.log('onFileValueChanged: ', fileVariable); }); ``` ``` -------------------------------- ### Get Events API Request Examples Source: https://developer.clevertap.com/docs/get-events-api Examples of how to call the Get Events API using cURL, Ruby, Python, PHP, Node.js, and Go. These examples demonstrate authentication and request body structure. ```APIDOC ## POST /1/events.json ### Description Retrieves event data from the CleverTap account. ### Method POST ### Endpoint `https://.api.clevertap.com/1/events.json` ### Query Parameters - **batch_size** (integer) - Optional - Specifies the number of events to retrieve per batch. ### Headers - **X-CleverTap-Account-Id** (string) - Required - Your CleverTap Account ID. - **X-CleverTap-Passcode** (string) - Required - Your CleverTap Passcode. - **Content-Type** (string) - Required - Must be `application/json`. ### Request Body - **event_name** (string) - Required - The name of the event to retrieve. - **from** (integer) - Required - The start date for the event data (YYYYMMDD format). - **to** (integer) - Required - The end date for the event data (YYYYMMDD format). ### Request Example (cURL) ```curl curl -X POST -d '{"event_name":"App Launched","from":20171201,"to":20171225}' "https://in1.api.clevertap.com/1/events.json?batch_size=50" \ -H "X-CleverTap-Account-Id: ACCOUNT_ID" \ -H "X-CleverTap-Passcode: PASSCODE" \ -H "Content-Type: application/json" ``` ### Response #### Success Response (200) - **cursor** (string) - A cursor for fetching the next batch of events. - **status** (string) - Indicates the status of the request, e.g., `success`. #### Response Example ```json { "cursor" : "AfljfgIJBgBnamF5Kz8NegcBAwxhbCe%2Fbmhhe04BBAVlYjT4YG5reQEATQQrai57K2oue04FAUhnd38%3D" , "status" : "success"} ``` ``` -------------------------------- ### Create Campaign with Labels Source: https://developer.clevertap.com/docs/create-campaign-api This example demonstrates how to create a campaign and attach multiple labels to it using the API. ```APIDOC ## Create Campaign with Labels ### Description Associates one or more labels with a campaign during creation for easier organization, searching, and filtering in the CleverTap dashboard. ### Method POST (Assumed, as it's a creation operation) ### Endpoint /campaigns (Assumed, based on typical API patterns for campaign creation) ### Parameters #### Request Body - **labels** (Array of strings) - Optional - A list of labels to attach to the campaign. These labels will be visible in the CleverTap dashboard under campaign details. Example: `["news", "sports"]` ### Request Example ```json { "name": "Test Labels", "estimate_only": false, "target_mode": "push", "labels": [ "news", "sports" ], "where": { "event_name": "App Launched", "from": 20250901, "to": 20250931, "common_profile_properties": { "profile_fields": [ { "name": "Customer Type", "operator": "equals", "value": "Platinum" } ] } }, "respect_frequency_caps": false, "content": { "title": "Hi!", "body": "How are you doing today?" }, "when": "now" } ``` ### Response #### Success Response (200) (Response schema not provided in source text, but would typically include campaign details) #### Response Example (Response example not provided in source text) ``` -------------------------------- ### Example JSON Response from Get Message Reports API Source: https://developer.clevertap.com/docs/get-message-reports-api This is an example of a successful JSON response from the Get Message Reports API, detailing message statistics and campaign information. ```json { "status": "success", "total_results": 1, "messages": [ { "message id": 1508323121, "data": [ [ { "sent": 0, "viewed": 0, "clicked": 0 } ] ], "start_date": "Oct 18, 4:08 PM", "device": [ "Android", "iOS", "WindowsMobile" ], "conversion_event": null, "labels": [], "status": "completed", "channel": "InApp", "message_name": "in_app_outputs_test", "delivery": "Action" } ] } ``` -------------------------------- ### Initialize RudderStack Client with CleverTap Source: https://developer.clevertap.com/docs/clevertap-rudderstack-react-native-integration Configure and set up the RudderStack client, including the CleverTap factory, data plane URL, and write key. ```javascript const config = { dataPlaneUrl : "YOUR_DATA_PLANE_URL", logLevel: 3, trackAppLifecycleEvents: true, recordScreenViews:true, withFactories: [clevertap] }; rudderClient.setup("YOUR_WRITE_KEY", config); ``` -------------------------------- ### Get Event Count API Response Examples Source: https://developer.clevertap.com/docs/get-event-count-api These JSON examples illustrate the possible responses from the Get Event Count API. They include success, partial, and error scenarios, detailing the structure and key fields for each. ```json { "status": "success", "count": 7138 } ``` ```json { "status": "partial", "req_id": 1234567890123456789 } ``` ```json { "status": "fail", "error": "Error message" } ``` -------------------------------- ### Start Geofence Monitoring (Objective-C) Source: https://developer.clevertap.com/docs/geofence-ios Initialize the CleverTapGeofence monitor in your application:didFinishLaunchingWithOptions: function after the main CleverTap SDK initialization. ```objectivec [[CleverTapGeofence monitor] startWithDidFinishLaunchingWithOptions:launchOptions]; ``` -------------------------------- ### Get Campaigns API Request Example (JavaScript) Source: https://developer.clevertap.com/docs/get-campaigns-api This JavaScript example uses the axios library to make a POST request to the Get Campaigns API. It includes the necessary headers and a JSON payload for the date range. ```javascript const axios = require("axios"); const url = "https://in1.api.clevertap.com/1/targets/list.json"; const headers = { "X-CleverTap-Account-Id": "ACCOUNT_ID", "X-CleverTap-Passcode": "PASSCODE", "Content-Type": "application/json", }; const data = { from: 20160101, to: 20160101 }; axios .post(url, data, { headers }) .then((res) => console.log(res.data)) .catch((err) => console.error(err.response?.data || err.message)); ``` -------------------------------- ### Initialize and Fetch Product Config Source: https://developer.clevertap.com/docs/flutter-advanced-features Initialize product configuration and fetch values from CleverTap. This should be called to load default values and prepare for fetching remote configurations. ```javascript Dart void productConfigInitialized() { print("Product Config Initialized"); this.setState(() async { await CleverTapPlugin.fetch(); }); } ``` -------------------------------- ### Node.js Example for Get Message Reports API Source: https://developer.clevertap.com/docs/get-message-reports-api This Node.js example uses the 'request' module to send a POST request to the Get Message Reports API. It includes configuration for the request options and a callback function to handle the response. ```javascript var request = require('request'); var headers = { 'X-CleverTap-Account-Id': 'ACCOUNT_ID', 'X-CleverTap-Passcode': 'PASSCODE', 'Content-Type': 'application/json' }; var dataString = '{"from":"20171101","to":"20171225"}'; var options = { url: 'https://in1.api.clevertap.com/1/message/report.json', method: 'POST', headers: headers, body: dataString }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } } request(options, callback); ``` -------------------------------- ### Set Up Callbacks Source: https://developer.clevertap.com/docs/ios-remote-config This section covers setting up various callbacks provided by the CleverTap iOS SDK to receive feedback, including callbacks for variables and file variables. ```APIDOC ## Set Up Callbacks ### Description Allows developers to register callbacks to receive feedback from the SDK regarding variable changes and initializations. ### All Variables Callbacks #### `onVariablesChanged` This callback is invoked when variables are initialized with values fetched from the server. It is called each time new values are fetched. ##### Swift Example ```swift let var_string = CleverTap.sharedInstance()?.defineVar(name: "myString", string: "hello,world") CleverTap.sharedInstance()?.onVariablesChanged { print("CleverTap.onVariablesChanged: \(var_string?.value ?? "")") } ``` ##### Objective-C Example ```objectivec #import CTVar *var_string = [[CleverTap sharedInstance] defineVar:@"var_string" withString:@"hello, world"]; [[CleverTap sharedInstance] onVariablesChanged:^{ NSLog(@"CleverTap.onVariablesChanged: %@", [var_string value]); }]; ``` ``` -------------------------------- ### Get Events API Source: https://developer.clevertap.com/docs/events-object The Get Events API lets you download user events from CleverTap. For example, you can use this API to get a list of Purchase events in the past week. ```APIDOC ## Get Events API ### Description Downloads user events from CleverTap. ### Method GET ### Endpoint /1/events ### Parameters #### Query Parameters - **event_name** (string) - Required - The name of the event to retrieve. - **from** (integer) - Required - The start of the time range in epoch milliseconds. - **to** (integer) - Required - The end of the time range in epoch milliseconds. ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **result** (array) - An array of event objects. - **event** (string) - The name of the event. - **ts** (integer) - The timestamp of the event in epoch milliseconds. - **type** (string) - The type of the event. - **objectId** (string) - The unique identifier for the event. - **profile** (object) - User profile information. - **objectId** (string) - The unique identifier for the user profile. - **ts** (integer) - The timestamp of the profile update in epoch milliseconds. - **attributes** (object) - User profile attributes. #### Response Example ```json { "status": "success", "result": [ { "event": "Purchase", "ts": 1678886400000, "type": "event", "objectId": "evt_12345", "profile": { "objectId": "usr_abcde", "ts": 1678886400000, "attributes": { "email": "test@example.com" } } } ] } ``` ``` -------------------------------- ### Alert Push Primer (C#) Source: https://developer.clevertap.com/docs/unity-push Use this to create a lightweight, system-style Push Primer notification. Ideal for quick, unobtrusive permission requests during mid-session nudges. ```csharp Dictionary item = new Dictionary(); item.Add("inAppType", "alert"); item.Add("titleText", "Get Notified"); item.Add("messageText", "Please enable notifications on your device to use Push Notifications."); item.Add("followDeviceOrientation", true); item.Add("fallbackToSettings", true); CleverTap.PromptPushPrimer(item); ``` -------------------------------- ### Get Wallet Details API Request Source: https://developer.clevertap.com/docs/get-wallet-details This example demonstrates how to make a GET request to the Get Wallet Details API. Ensure you include your Account ID and Passcode in the headers for authentication. ```curl curl -X GET "https://in1.api.clevertap.com/1/promo/wallets?identity=krishna123" \ -H "X-CleverTap-Account-Id: ACCOUNT_ID" \ -H "X-CleverTap-Passcode: PASSCODE" \ -H "Content-Type: application/json" ``` -------------------------------- ### getLocalInAppSettings Source: https://developer.clevertap.com/docs/push-notifications-ios Retrieves a dictionary containing all parameters required for displaying the push primer. This dictionary is then passed as an argument to the `promptPushPrimer` method. ```APIDOC ## getLocalInAppSettings ### Description Returns a dictionary containing all parameters for push primer settings. ### Method Objective-C Method ### Signature `(NSDictionary *)getLocalInAppSettings` ### Returns - `NSDictionary` - A dictionary containing all parameters for push primer settings. ``` -------------------------------- ### Get Event Count Source: https://developer.clevertap.com/docs/get-event-count-api Retrieve counts for an event in a specified duration. For example, you can get the total number of charge events in the past day. ```APIDOC ## POST /1/counts/events.json ### Description Retrieve counts for an event in a specified duration. ### Method POST ### Endpoint /1/counts/events.json ### Headers Refer [Headers](https://developer.clevertap.com/docs/common-api-components#headers) for more details. ### Body Parameters The body is uploaded as a JSON payload. - **event_name** (string) - Required - The name of the event. - **event_properties** (string key/value pairs) - Optional - The event properties that you want to filter the results on. - **from** (int) - Required - Start of date range within which users should have performed the event you specified in event_name. Input values have to be formatted as integers in format YYYYMMDD. - **to** (int) - Required - End of date range within which users should have performed the event you specified in event_name. Input values have to be formatted as integers in format YYYYMMDD. ### Request Example ```json { "event_name": "choseNewFavoriteFood", "event_properties": [ { "name": "value", "operator": "contains", "value": "piz" } ], "from": 20150810, "to": 20151025 } ``` ### Response #### Success Response (200) - **count** (int) - The number of events matching the criteria. #### Response Example ```json { "count": 150 } ``` ``` -------------------------------- ### Example User Response Source: https://developer.clevertap.com/docs/add-user-api This is a sample response when a user is successfully added. It includes the user's ID, schema, username, name details, active status, account information, and who invited them. ```json { "id": "user-unique-id", "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"], "userName": "jane.smith@example.com", "name": { "givenName": "Jane", "familyName": "Smith" }, "active": true, "accounts": [ { "accountId": "CLEVERTAP_ACCOUNT_ID", "roles": "Editor", "teams": "Marketing", "status": "Active" } ], "invitedBy": "admin@example.com" } ``` -------------------------------- ### Delete User Profile Request Body Examples Source: https://developer.clevertap.com/docs/delete-user-profile-api Examples of valid JSON payloads for deleting user profiles. Ensure either 'identity' or 'guid' is present. ```json { "identity": ["client-19827239", "abc"] } OR { "identity": "client-19827239" } OR { "guid": ["ctid123", "ctid456"] } OR { "guid": "clientid123" } ``` -------------------------------- ### Get Campaigns API Response Example Source: https://developer.clevertap.com/docs/get-campaigns-api This is a sample JSON response from the Get Campaigns API, showing a list of campaigns with their IDs, names, scheduled times, and statuses. ```json { "status": "success", "targets": [ { "id": 1457429935, "name": "My API Campaign", "scheduled_on": 201601011508, "status": "pending" }, { "id": 1457432766, "name": "My API Campaign 2", "scheduled_on": 201601011556, "status": "completed" } ] } ``` -------------------------------- ### Push Primer using Alert In-App (Kotlin) Source: https://developer.clevertap.com/docs/android-in-app-notifications Example of creating and displaying a basic push primer notification using the ALERT InApp type in Kotlin. ```APIDOC ## Push Primer using Alert In-App (Kotlin) You can use this template to send a basic push primer notification with a title, message, and two buttons. ```kotlin val builder = CTLocalInApp.builder() .setInAppType(CTLocalInApp.InAppType.ALERT) .setTitleText("Get Notified") .setMessageText("Enable Notification permission") .followDeviceOrientation(true) .setPositiveBtnText("Allow") .setNegativeBtnText("Cancel") .build() cleverTapAPI.promptPushPrimer(builder) ``` ``` -------------------------------- ### Get User Profiles API cURL Request Source: https://developer.clevertap.com/docs/get-user-profiles-api Example cURL request to the Get User Profiles API, demonstrating the necessary headers for authentication and the JSON payload for the request. ```curl curl -X POST -d '{"event_name":"App Launched","from":20171201,"to":20171225}' "https://in1.api.clevertap.com/1/profiles.json?batch_size=50" \ -H "X-CleverTap-Account-Id: ACCOUNT_ID" \ -H "X-CleverTap-Passcode: PASSCODE" \ -H "Content-Type: application/json" ``` -------------------------------- ### Half Interstitial Push Primer (C#) Source: https://developer.clevertap.com/docs/unity-push Use this to create a visually rich Push Primer with custom branding and elements. Configure appearance and button text for a branded onboarding experience. ```csharp Dictionary item = new Dictionary(); item.Add("inAppType", "half-interstitial"); item.Add("titleText", "Get Notified"); item.Add("messageText", "Please enable notifications on your device to use Push Notifications."); item.Add("followDeviceOrientation", true); item.Add("positiveBtnText", "Allow"); item.Add("negativeBtnText", "Cancel"); item.Add("backgroundColor", "#FFFFFF"); item.Add("btnBorderColor", "#0000FF"); item.Add("titleTextColor", "#0000FF"); item.Add("messageTextColor", "#000000"); item.Add("btnTextColor", "#FFFFFF"); item.Add("btnBackgroundColor", "#0000FF"); item.Add("imageUrl", "https://icons.iconarchive.com/icons/treetog/junior/64/camera-icon.png"); item.Add("btnBorderRadius", "2"); item.Add("fallbackToSettings", true); CleverTap.PromptPushPrimer(item); ``` -------------------------------- ### Example Request to Get Events using Cursor Source: https://developer.clevertap.com/docs/api-encryption Demonstrates how to make a GET request to retrieve events using a cursor, requesting an encrypted response via the Accept header. ```APIDOC ## Example Request to Get Events using Cursor For GET requests, there is no request body to encrypt. Use the *Accept* header to request an encrypted response. ```java // Cursor from Step 2 String cursor = "AfljfgIJBgBnamF5Kz8NegcBAwxhbCe%2Fbmhhe04BBAVlYjT4YG5reQEATQQrai57K2oue04FAUhnd38%3D"; // Build and send the GET request HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.clevertap.com/1/events.json?cursor=" + cursor)) .header("X-CleverTap-Account-Id", ENCODED_ACCOUNT_ID) .header("X-CleverTap-Passcode", PASSCODE) .header("Content-Type", "application/json") .header("Accept", "application/octet-stream+hpke") .GET() .build(); // Execute request HttpResponse response = client.send( request, HttpResponse.BodyPublishers.ofByteArray() ); ``` ``` -------------------------------- ### Set Product Configuration to Default Source: https://developer.clevertap.com/docs/react-native-advanced-features Initialize product config and listen for initialization events. Set default values for product config keys. ```APIDOC ## Set Product Configuration to Default ### Description Initialize product config and listen for initialization events. Set default values for product config keys. ### Method ```javascript JavaScript CleverTap.addListener(CleverTap.CleverTapProductConfigDidInitialize, (data) => { // Called when Product Config is initialized }); CleverTap.setDefaultsMap({ 'text_color': 'red', 'msg_count': 100, 'price': 100.50, 'is_shown': true, 'json': '{"key":"val"}' // JSON string example }); ``` ### Parameters #### Path Parameters - **CleverTapProductConfigDidInitialize** (string) - Required - The event name for product config initialization. - **data** (object) - Required - Data related to product config initialization. - **Defaults Map** (object) - Required - A map of default values for product config keys. ``` -------------------------------- ### Fetch Product Configurations Source: https://developer.clevertap.com/docs/cordova-advance-features Initiate a fetch for the latest product configurations from the server. An event listener is provided to confirm when the fetch operation is complete. ```javascript CleverTap.fetch() document.addEventListener('onCleverTapProductConfigDidFetch', () => log("onCleverTapProductConfigDidFetch")) ``` -------------------------------- ### PHP Example for Get Message Reports API Source: https://developer.clevertap.com/docs/get-message-reports-api This PHP script utilizes the Requests library to interact with the Get Message Reports API. It demonstrates setting up headers and the request payload. ```php 'ACCOUNT_ID', 'X-CleverTap-Passcode' => 'PASSCODE', 'Content-Type' => 'application/json' ); $data = '{"from":"20171101","to":"20171225"}'; $response = Requests::post('https://in1.api.clevertap.com/1/message/report.json', $headers, $data); ?> ``` -------------------------------- ### Register Product Config Listener (Objective-C) Source: https://developer.clevertap.com/docs/product-experiences-ios Implement the CleverTapProductConfigDelegate protocol in your class and assign it to the product config delegate to receive initialization, fetch, and activation callbacks. ```objectivec #import "ViewController.h" #import #import @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; ... [CleverTap sharedInstance].productConfig.delegate = self; } @end ``` -------------------------------- ### Get Campaigns API Request Example (cURL) Source: https://developer.clevertap.com/docs/get-campaigns-api This cURL command demonstrates how to make a POST request to the Get Campaigns API. Include your account ID, passcode, and the JSON payload. ```curl curl -X POST \ "https://in1.api.clevertap.com/1/targets/list.json" \ -H "X-CleverTap-Account-Id: ACCOUNT_ID" \ -H "X-CleverTap-Passcode: PASSCODE" \ -H "Content-Type: application/json" \ -d '{ "from": 20160101, "to": 20160101 }' ``` -------------------------------- ### Push Primer using Alert In-App (Java) Source: https://developer.clevertap.com/docs/android-in-app-notifications Example of creating and displaying a basic push primer notification using the ALERT InApp type in Java. ```APIDOC ## Push Primer using Alert In-App (Java) Use the following to create your template: ```java JSONObject jsonObject = CTLocalInApp.builder() .setInAppType(CTLocalInApp.InAppType.ALERT) .setTitleText("Get Notified") .setMessageText("Enable Notification permission") .followDeviceOrientation(true) .setPositiveBtnText("Allow") .setNegativeBtnText("Cancel") .build(); cleverTapAPI.promptPushPrimer(jsonObject); ``` ``` -------------------------------- ### Get User Profiles Using Cursor (Node.js) Source: https://developer.clevertap.com/docs/get-user-profiles-api This Node.js example shows how to use the 'request' module to call the Get User Profiles API. It includes setting headers and the cursor for pagination. ```javascript var request = require('request'); var headers = { 'X-CleverTap-Account-Id': 'ACCOUNT_ID', 'X-CleverTap-Passcode': 'PASSCODE', 'Content-Type': 'application/json' }; var options = { url: 'https://api.clevertap.com/1/profiles.json?cursor=CURSOR', headers: headers }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } } request(options, callback); ``` -------------------------------- ### Start Geofence Monitoring (Swift) Source: https://developer.clevertap.com/docs/geofence-ios Initialize the CleverTapGeofence monitor in your application:didFinishLaunchingWithOptions: function after the main CleverTap SDK initialization. ```swift CleverTapGeofence.monitor.start(didFinishLaunchingWithOptions: launchOptions) ``` -------------------------------- ### Example cURL Request to Get Message Reports Source: https://developer.clevertap.com/docs/get-message-reports-api Use this cURL command to authenticate and send a request to the Get Message Reports API. Ensure you replace ACCOUNT_ID and PASSCODE with your actual credentials. ```curl curl -X POST -d '{"from":"20171101","to":"20171225"}' "https://in1.api.clevertap.com/1/message/report.json" \ -H "X-CleverTap-Account-Id: ACCOUNT_ID" \ -H "X-CleverTap-Passcode: PASSCODE" \ -H "Content-Type: application/json" ``` -------------------------------- ### Install CleverTap Web SDK with Yarn Source: https://developer.clevertap.com/docs/web-quickstart-guide Use this command to install the CleverTap Web SDK using the yarn package manager. ```bash yarn add clevertap-web-sdk ``` -------------------------------- ### Get Event Count using Python Source: https://developer.clevertap.com/docs/get-event-count-api This Python example uses the 'requests' library to make a POST request to the Get Event Count API. It shows how to define headers and the request payload. ```python import requests headers = { 'X-CleverTap-Account-Id': 'ACCOUNT_ID', 'X-CleverTap-Passcode': 'PASSCODE', 'Content-Type': 'application/json', } data = '{"event_name":"choseNewFavoriteFood","event_properties":[{"name":"value","operator":"contains","value":"piz"}],"from":20150810,"to":20151025}' response = requests.post('https://in1.api.clevertap.com/1/counts/events.json', headers=headers, data=data) ``` -------------------------------- ### Make a POST Request to Get Campaign Report API (cURL) Source: https://developer.clevertap.com/docs/get-campaign-report-api Example of how to call the Get Campaign Report API using cURL. Ensure you replace ACCOUNT_ID and PASSCODE with your actual credentials. ```curl curl -X POST \ "https://in1.api.clevertap.com/1/targets/result.json" \ -H "X-CleverTap-Account-Id: ACCOUNT_ID" \ -H "X-CleverTap-Passcode: PASSCODE" \ -H "Content-Type: application/json" \ -d '{ "id": 1457432766 }' ``` -------------------------------- ### Register Product Config Listener (Swift) Source: https://developer.clevertap.com/docs/product-experiences-ios Implement the CleverTapProductConfigDelegate protocol in your class and assign it to the product config delegate to receive initialization, fetch, and activation callbacks. ```swift import UIKit import CleverTapSDK class ViewController: UIViewController, CleverTapProductConfigDelegate { override func viewDidLoad() { super.viewDidLoad() ... CleverTap.sharedInstance()?.productConfig.delegate = self; } } ``` -------------------------------- ### Install mParticle Web SDK via npm Source: https://developer.clevertap.com/docs/mparticle-web-integration Integrate the mParticle Web SDK into your project using npm for easier dependency management. ```bash npm i @mparticle/web-sdk ``` -------------------------------- ### Python Example for Get Message Reports API Source: https://developer.clevertap.com/docs/get-message-reports-api This Python script uses the requests library to send a POST request to the Get Message Reports API. It shows how to configure headers and data for the request. ```python import requests headers = { 'X-CleverTap-Account-Id': 'ACCOUNT_ID', 'X-CleverTap-Passcode': 'PASSCODE', 'Content-Type': 'application/json', } data = '{"from":"20171101","to":"20171225"}' response = requests.post('https://in1.api.clevertap.com/1/message/report.json', headers=headers, data=data) ``` -------------------------------- ### Get Profile Count using Go Source: https://developer.clevertap.com/docs/get-profile-count-api This Go example shows how to construct and send a POST request to the Get Profile Count API. It defines a struct for the payload, marshals it to JSON, and sets the necessary headers. ```go type Payload struct { EventName string `json:"event_name"` EventProperties []struct { Name string `json:"name"` Operator string `json:"operator"` Value string `json:"value"` } `json:"event_properties"` From int `json:"from"` To int `json:"to"` } data := Payload{ // fill struct } payloadBytes, err := json.Marshal(data) if err != nil { // handle err } body := bytes.NewReader(payloadBytes) req, err := http.NewRequest("POST", "https://in1.api.clevertap.com/1/counts/profiles.json", body) if err != nil { // handle err } req.Header.Set("X-Clevertap-Account-Id", "ACCOUNT_ID") req.Header.Set("X-Clevertap-Passcode", "PASSCODE") req.Header.Set("Content-Type", "application/json") resp, err := http.DefaultClient.Do(req) if err != nil { // handle err } defer resp.Body.Close() ``` -------------------------------- ### Push Install Referrer Data Source: https://developer.clevertap.com/docs/unity-advanced-features Attribute installs accurately by passing campaign parameters like source, medium, and campaign. Call this after capturing parameters with attribution SDKs. ```csharp CleverTap.PushInstallReferrerSource("source", "medium", "campaign"); // Call this after capturing campaign parameters using attribution SDKs like InstallReferrerClient for Android. ``` -------------------------------- ### Get Profile Count using Python Source: https://developer.clevertap.com/docs/get-profile-count-api This Python example uses the requests library to send a POST request to the Get Profile Count API. It includes the required headers and a JSON string for the request body. ```python import requests headers = { 'X-CleverTap-Account-Id': 'ACCOUNT_ID', 'X-CleverTap-Passcode': 'PASSCODE', 'Content-Type': 'application/json', } data = '{"event_name":"choseNewFavoriteFood","event_properties":[{"name":"value","operator":"contains","value":"piz"}],"from":20150810,"to":20151025}' response = requests.post('https://in1.api.clevertap.com/1/counts/profiles.json', headers=headers, data=data) ``` -------------------------------- ### Get Campaigns API Request Example (Python) Source: https://developer.clevertap.com/docs/get-campaigns-api This Python script uses the requests library to make a POST request to the Get Campaigns API. It includes the necessary headers and a JSON payload for the date range. ```python import requests url = "https://in1.api.clevertap.com/1/targets/list.json" headers = { "X-CleverTap-Account-Id": "ACCOUNT_ID", "X-CleverTap-Passcode": "PASSCODE", "Content-Type": "application/json", } payload = { "from": 20160101, "to": 20160101 } response = requests.post(url, headers=headers, json=payload) print(response.json()) ``` -------------------------------- ### Handle Launcher Activity Create (Java) Source: https://developer.clevertap.com/docs/unity-sdk-quick-start-guide-sdk-v300 Include this code in your custom Launcher Activity's `onCreate` method to properly initialize CleverTap's handling of the launcher activity. ```java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CleverTapUnityAPI.onLauncherActivityCreate(this); } ``` -------------------------------- ### Create and Use Multiple CleverTap Instances Source: https://developer.clevertap.com/docs/multi-instance-support-android Demonstrates how to create a new CleverTap instance with a specific configuration and push profile updates. Use this for managing distinct user segments or data streams. ```java CleverTapInstanceConfig config = CleverTapInstanceConfig.createInstance(this,"YOUR_ACCOUNT_ID","YOUR_ACCOUNT_TOKEN"); CleverTapAPI cleverTapAPI = CleverTapAPI.instanceWithConfig(this,config); //Push a simple profile update HashMap profileUpdate = new HashMap(); profileUpdate.put("Customer Type", "Silver"); profileUpdate.put("Prefered Language", "English"); cleverTapAPI.profile.push(profileUpdate); //Push a complex profile update HashMap profileUpdate = new HashMap(); profileUpdate.put("Name", "Jack Montana"); // String profileUpdate.put("Identity", 61026032); // String or number profileUpdate.put("Email", "jack@gmail.com"); // Email address of the user profileUpdate.put("Phone", "+14155551234"); // Phone (with the country code, starting with +) profileUpdate.put("Gender", "M"); // Can be either M or F profileUpdate.put("Employed", "Y"); // Can be either Y or N profileUpdate.put("Education", "Graduate"); // Can be either Graduate, College or School profileUpdate.put("Married", "Y"); // Can be either Y or N profileUpdate.put("DOB", new Date()); // Date of Birth. Set the Date object to the appropriate value first profileUpdate.put("Age", 28); // Not required if DOB is set profileUpdate.put("Tz", "Asia/Kolkata"); //an abbreviation such as "PST", a full name such as "America/Los_Angeles", //or a custom ID such as "GMT-8:00" profileUpdate.put("Photo", "www.foobar.com/image.jpeg"); // URL to the Image // optional fields. controls whether the user will be sent email, push etc. profileUpdate.put("MSG-email", false); // Disable email notifications profileUpdate.put("MSG-push", true); // Enable push notifications profileUpdate.put("MSG-sms", false); // Disable SMS notifications ArrayList stuff = new ArrayList(); stuff.add("bag"); stuff.add("shoes"); profileUpdate.put("MyStuff", stuff); //ArrayList of Strings String[] otherStuff = {"Jeans","Perfume"}; profileUpdate.put("MyStuff", otherStuff); //String Array cleverTapAPI.pushProfile(profileUpdate); ``` -------------------------------- ### Ruby Example for Get Message Reports API Source: https://developer.clevertap.com/docs/get-message-reports-api This Ruby script demonstrates how to make a POST request to the Get Message Reports API using the Net::HTTP library. It includes setting headers and the request body. ```ruby require 'net/http' require 'uri' require 'json' uri = URI.parse("https://in1.api.clevertap.com/1/message/report.json") request = Net::HTTP::Post.new(uri) request.content_type = "application/json" request["X-Clevertap-Account-Id"] = "ACCOUNT_ID" request["X-Clevertap-Passcode"] = "PASSCODE" request.body = JSON.dump({ "from" => "20171101", "to" => "20171225" }) req_options = { use_ssl: uri.scheme == "https", } response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| http.request(request) end ``` -------------------------------- ### Get Event Count using JavaScript Source: https://developer.clevertap.com/docs/get-event-count-api This JavaScript example uses the 'request' module to make a POST request to the Get Event Count API. It includes defining request options and a callback function to handle the response. ```javascript var request = require('request'); var headers = { 'X-CleverTap-Account-Id': 'ACCOUNT_ID', 'X-CleverTap-Passcode': 'PASSCODE', 'Content-Type': 'application/json' }; var dataString = '{"event_name":"choseNewFavoriteFood","event_properties":[{"name":"value","operator":"contains","value":"piz"}],"from":20150810,"to":20151025}'; var options = { url: 'https://in1.api.clevertap.com/1/counts/events.json', method: 'POST', headers: headers, body: dataString }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } } request(options, callback); ``` -------------------------------- ### Install CleverTap Web SDK with npm Source: https://developer.clevertap.com/docs/web-quickstart-guide Use this command to install the CleverTap Web SDK using the npm package manager. ```bash npm install clevertap-web-sdk --save ``` -------------------------------- ### Fetch and Activate Product Config Source: https://developer.clevertap.com/docs/cordova-advance-features Fetches the latest product configurations and immediately activates them. ```APIDOC ## Fetch And Activate product config ```javascript JavaScript CleverTap.fetchAndActivate(); ``` ``` -------------------------------- ### Get Campaigns API Request Example (Ruby) Source: https://developer.clevertap.com/docs/get-campaigns-api This Ruby script shows how to send a POST request to the Get Campaigns API using the Net::HTTP library. Ensure you set the correct headers and JSON payload. ```ruby require 'net/http' require 'uri' require 'json' uri = URI.parse("https://in1.api.clevertap.com/1/targets/list.json") request = Net::HTTP::Post.new(uri) request["X-CleverTap-Account-Id"] = "ACCOUNT_ID" request["X-CleverTap-Passcode"] = "PASSCODE" request["Content-Type"] = "application/json" request.body = { from: 20160101, to: 20160101 }.to_json response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end puts response.body ``` -------------------------------- ### Register Listener for Product Config Callbacks Source: https://developer.clevertap.com/docs/product-experiences-ios Implement the CleverTapProductConfigDelegate protocol and assign it to the productConfig delegate to receive callbacks for initialization, fetching, and activation of product configurations. ```APIDOC ## Register Listener to Receive Product Config Callbacks Implement the `CleverTapProductConfigDelegate` protocol and set the delegate to receive callbacks. ### Swift Example ```swift import UIKit import CleverTapSDK class ViewController: UIViewController, CleverTapProductConfigDelegate { override func viewDidLoad() { super.viewDidLoad() CleverTap.sharedInstance()?.productConfig.delegate = self; } // Implement delegate methods func ctProductConfigInitialized() { print("Product Config Initialized") } func ctProductConfigFetched() { print("Product Config Fetched") } func ctProductConfigActivated() { print("Product Config Activated") } } ``` ### Objective-C Example ```objectivec #import "ViewController.h" #import #import @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [CleverTap sharedInstance].productConfig.delegate = self; } // Implement delegate methods - (void)ctProductConfigInitialized { NSLog(@"Product Config Initialized"); } - (void)ctProductConfigFetched { NSLog(@"Product Config Fetched"); } - (void)ctProductConfigActivated { NSLog(@"Product Config Activated"); } @end ``` ```