Encrypting Parameters in a TUNE Link

While measuring ads with the Measurement API for clicks and/or impressions doesn't require authentication, the Measure Ads endpoints do allow you to include an encrypted payload of data.

This is useful if you are using client-side impression notifications or client-side click redirects and want to include cost data dynamically in the requests to measure the ads, but would prefer the actual amount not to be displayed in plain text in the URL.

Below is an example TUNE link when charging your client on a CPC basis at the rate (bid won) of $0.01 per click:

https://publisher_id.measure.mobileapptracking.com/serve?action=click
&publisher_id=19228
&site_id=2962
&ios_ifa=AAAAAA-BBBB-CCCC-11111-2222222222222
&cost_model=cpc
&cost=0.01

If you would prefer the cost model and cost parameters to not be set in plain text like in the above example, you can encrypt the data and include it in an encrypted data payload.

Below is the same example TUNE link from above, but &cost_model=cpc&cost=0.01 is encrypted and included in the the value of the data parameter:

https://publisher_id.measure.mobileapptracking.com/serve?action=click
&publisher_id=19228
&site_id=2962
&ios_ifa=AAAAAA-BBBB-CCCC-11111-2222222222222
&ckey=STRING32CHARACTERS11223344556677
&data=71b85c10d2427146dc24007c610ea647823465febf2447560d6fc02a33bd0207

Keys and Parameters

Each request in which you'd like to include an encrypted data payload, requires a Public key (Consumer Key) which is then encrypted using a Private Key.

  • Private Key – used to generate the signature on both the client and server but will not be included in the request.
  • Consumer Key – included with each request so that the Private Key used to create the signature can be identified.

To obtain a Private Key, please read Obtaining Your Private API Key.

To obtain a Consumer Key, please contact your TUNE Sales Engineer.

We use strings of 32 characters long for encrypting the data payload (for clicks and impressions), measuring sessions, and measuring events with the Measurement API.

The Private Key is used to create the encrypted data payload. The Consumer Key will then need to be included outside of the encrypted data payload in plain text so it can then be used to find the Private Key and encrypted data payload. Thus, you will replace the key values you want to be encrypted with the following two parameters:

  • ckey – Consumer Key
  • data – Encrypted data payload of parameters; generating the value for the data parameter is described in the following section.

Generating the Encrypted Data Payload

Any key value parameters you prefer not to include as plain text in the request URL can be included in the encrypted data payload.
In the PHP example below, we are hashing cost_model=cpc and cost=0.1

$consumer_key = 'STRING32CHARACTERS11223344556677';
$private_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
 
$params = array(
'cost' => 0.01,
'cost_model' => 'cpc'
);
$mcrypt_iv = substr($consumer_key, 0, 16);
$query_str = http_build_query($params);
 
$enc_raw = mcrypt_encrypt( MCRYPT_RIJNDAEL_128, $private_key, $query_str, 'cbc', $mcrypt_iv);
$enc_str = bin2hex( $enc_raw );
 
echo $enc_str ;

After you've generated the encrypted data payload, you'll need to include it in the URL along with the ckey parameter as seen in the example below.

https://publisher_id.measure.mobileapptracking.com/serve?action=click
&publisher_id=19228
&site_id=2962
&ios_ifa=AAAAAA-BBBB-CCCC-11111-2222222222222
&ckey=STRING32CHARACTERS11223344556677
&data=71b85c10d2427146dc24007c610ea647823465febf2447560d6fc02a33bd0207

The Measurement API will then decrypt the data payload and set the parameters accordingly.

Encrypting Additional Parameters

You can include all of the parameters in a request to measure a click or impression, but the action, ckey and data parameters will still need to set in the request. If this was the request URL with plain text values for keys:

https://publisher_id.measure.mobileapptracking.com/serve?action=click
&publisher_id=19228
&site_id=2962
&ios_ifa=AAAAAA-BBBB-CCCC-11111-2222222222222
&cost_model=cpc
&cost=0.01

The publisher_id, site_id, ios_ifa cost_model and cost parameters can all be included in the encrypted data payload, resulting in a similar URL below:

 
https://publisher_id.measure.mobileapptracking.com/serve?action=click
&ckey=STRING32CHARACTERS11223344556677
&data=424365febf2447560d671b85cag130d2427143dfga6d24007c6103ea6478dfga3465febf244760ds6fc02ad3adsf3bd0200sd7jf
Have a Question? Please contact support@tune.com for technical support.