iOS Custom Proxy Domain

Custom Proxy Domain

A custom proxy domain allows you to proxy all events raised from the CleverTap SDK through your required domain. If you want to use your application server, use a proxy domain to handle and/or relay CleverTap events. We provide custom domain support for Push Impression event handling.

Why is it useful?

Using a custom proxy domain has the following benefits:

  1. Use your own domain to collect data.
  2. Have fine control over filtering, auditing, and/or cleaning data before sending it to CleverTap.
  3. Turn event collection on or off across all platforms quickly.
  4. If you want to use your own application server, you can use a proxy domain to handle and/or relay CleverTap events.

You must have a domain and access to DNS site settings to set up the proxy domain. To create an AWS Certificate and CloudFront distribution for the proxy domain, perform the steps listed in the following sections, and then integrate CleverTap SDK with your proxy domain configuration.

AWS Certificate Manager

To create a certificate using ACM in the required region:

  1. Go to Certificate Manager in AWS.
  2. Click Request Certificate and select Request a public certificate.
2793

Request a Public Certificate

  1. Add the proxy domain name that you want to use. This proxy domain name relays events to CleverTap's origin domain. For example, subdomain.domain.com.
2782

Add the Proxy Domain Name

  1. Select a validation method based on your domain account permission.
2786

Select Validation Method

  1. After review, confirm and request the certificate.
  2. Copy the CNAME record from AWS Certificate Manager (ACM) details to add it to your domain registrar settings.
2794

CNAME Record in AWS Certificate Manager (ACM)

  1. Add the CNAME record in DNS Settings as shown below:
2795

Add CNAME in DNS

The ACM Validation status should update from Pending to Success in some time. This certificate is used for creating CloudFront distribution.

AWS CloudFront Distribution

Origin

  1. Enter Origin Domain: eu1.clevertap-prod.com.
  2. Select Protocol: HTTPS.
1436

Configure Origin Domain and Protocol

Default Cache Behaviour:

  1. Select Redirect HTTP to HTTPS as the Viewer protocol policy.
  2. Select GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE as the Allowed HTTP methods.
1280

Configure Viewer Section

  1. Under Cache key and origin requests, select Cache policy and origin request policy (recommended) option and select CachingOptimized from the list.
1405

Configure Cache Key and Origin Requests

Settings

  1. Add proxy name in Alternate domain name (CNAME) - optional: analytics.sdktesting.xyz. This is the same proxy used earlier to create the AWS certificate.

  2. Select the certificate created earlier in Custom SSL certificate - optional.

1202

Configure Alternate Domain Name (CNAME) and Custom SSL Certificate

  1. Select the recommended option under Security policy.
1421

Configure Security Policy

  1. Keep the other settings at default selection and click Create Distribution.
1405

Create Distribution

  1. Add another CNAME in DNS Settings to point your subdomain (analytics in this case) to the CloudFront distribution, as shown in the following image:
1912

Add CNAME in DNS Settings

  1. After the CloudFront distribution is deployed, enter the proxy domain in the browser address to check if the settings are working correctly.

Integrate CleverTap to use Proxy Domain

Using Autointegrate API

  1. Add your CleverTap credentials in the Info.plist file of your application.
  2. Insert the Account ID and Account Token values from your CleverTap account against the CleverTapAccountID and CleverTapToken keys.
  3. Add the CleverTapProxyDomain key with the proxy domain value for handling events through the custom proxy domain.
  4. Add the CleverTapSpikyProxyDomain key with proxy domain value for handling push impression events.
942

Integrate CleverTap to Use Proxy Domain

  1. Import the CleverTap SDK in your AppDelegate file and call CleverTap's autoIntegrate method in the didFinishLaunchingWithOptions: method.
CleverTap.autoIntegrate()
  1. Use CleverTap's sharedInstance to log events.
CleverTap.sharedInstance()?.recordEvent("Product viewed")

Using setCredentials API

  1. Import the CleverTap SDK and call either the setCredentialsWithAccountID:token:proxyDomain: method or the setCredentialsWithAccountID:token:proxyDomain:spikyProxyDomain: method.
CleverTap.setCredentialsWithAccountID(accountID: ACCOUNT_ID, token: ACCOUNT_TOKEN, proxyDomain: "analytics.sdktesting.xyz")
CleverTap.setCredentialsWithAccountID(accountID: ACCOUNT_ID, token: ACCOUNT_TOKEN, proxyDomain: "analytics.sdktesting.xyz", spikyProxyDomain: "spiky-analytics.sdktesting.xyz")
  1. Use CleverTap's sharedInstance to log events.
CleverTap.sharedInstance()?.recordEvent("Product viewed")

Create CleverTap's Additional Instance

  1. Call CleverTapInstanceConfig constructor with either of the following APIs:
let ctConfig = CleverTapInstanceConfig(accountId: ACCOUNT_ID, accountToken: ACCOUNT_TOKEN, proxyDomain: "analytics.sdktesting.xyz")
let ctConfig = CleverTapInstanceConfig(accountId: ACCOUNT_ID, accountToken: ACCOUNT_TOKEN, proxyDomain: "analytics.sdktesting.xyz", spikyProxyDomain: "spiky-analytics.sdktesting.xyz")
  1. Start the CleverTap instance by calling the CleverTap.instance(with:) method with the CleverTapInstanceConfig object you created earlier.
let cleverTapProxyInstance = CleverTap.instance(with: ctConfig)
  1. Use this instance to log events.
cleverTapProxyInstance.recordEvent("Product viewed")

Debug and Test

After integration, the logged events are available on the CleverTap dashboard. Use CleverTapInstanceConfig's logLevel instance variable or CleverTap.setDebugLevel(1) to debug requests and response.