Encrypting Tracking Link Parameters

AppsFlyer allows its integrated partners to encrypt tracking link parameters which they would not like to appear in plain text. This is useful if you are sending impression and/or click data to AppsFlyer containing the cost data but would prefer the actual amount not to be displayed in plain text in the URL.

An example of a tracking link before encryption:

http://app.appsflyer.com/id346547777?

pid=networkName

&c=campaignName

&idfa=abcd24fdsfsad

&af_cost_model=cpc

&af_cost_value=0.05

&af_siteid =12345

 

A tracking link after encrypting the cost fields:

http://app.appsflyer.com/id346547777?

&pid=networkName

&c=campaignName

&idfa=abcd24fdsfsad

&af_siteid =12345

&af_enc_data=2646c42d0a7d49e4a89917cff76e35ab

Steps for Encryption

  1. Contact your Partner Development Manager or reach out to partners@appsflyer.com to receive a key for encryption.
  2. Choose the fields you want to encrypt (e.g. af_cost_model, af_cost_value).
  3. Encrypt the data with the provided key. Encryption should be performed by using AES (see code sample below).
  4. Include the encrypted data in the tracking link under the af_enc_data field.
  5. (Optional) If required, you can include site_id as part of the encrypted fields to increase the entropy (e.g. the randomness of the security).

Below is a code sample in php for the encryption process:

PHP

<?php
$f = fopen( 'php://stdin', 'r' );
echo "Enter private key: ";
$private_key = trim(fgets($f));
echo "Enter cost model: ";
$cost_model = trim(fgets($f));
echo "Enter cost value : ";
$cost_value = trim(fgets($f));
echo "Enter cost currency : ";
$cost_currency = trim(fgets($f));
$params = array(
'af_cost_model' => $cost_model,
'af_cost_value' => $cost_value,
'af_cost_currency' => $cost_currency
);
$query_str = http_build_query($params);
$block_size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
$padding_size = $block_size - (strlen($query_str) % $block_size);
$padded_query_str = $query_str . str_repeat(chr($padding_size), $padding_size);
$enc_raw = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $private_key, $padded_query_str, "ecb");
$enc_b64 = base64_encode($enc_raw);
$enc_url_encoded = urlencode($enc_b64);
echo "\n\n\r";
echo "Private key: " . $private_key . "\r\n";
echo "Query string: " . $query_str . "\r\n";
echo "\n\r";
echo "Encrypted query string: " . $enc_url_encoded . "\r\n";
fclose( $f );
?>

JAVA

private static final String CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
private static final String encryptionKey = "XXXXXXXXXXXXXXXX";  // secret key provided by appsflyer
private static final SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes(), "AES");
public static void main(String[] args) throws Exception {
   String queryParams = "bid_value=0.01&bid_type=cpc";
   String cipher = encrypt(queryParams);
   System.out.println(cipher);
}
public static String encrypt(String str) throws Exception {
   Cipher cipherEncrypt = Cipher.getInstance(CIPHER_ALGORITHM);
   cipherEncrypt.init(Cipher.ENCRYPT_MODE, key);
   byte[] cipher = cipherEncrypt.doFinal(str.getBytes("UTF-8"));
   String b64 = encode64(cipher);
   String result = urlencode(b64);
   return result;
}
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request
Powered by Zendesk