背景:
在facebook的应用推广中,一般使用两种方式,一种是app直投,一种是w2a。
app直投就是用户点击广告直接跳转到应用商店进行下载应用
w2a就是通过落地页方式引导用户进行应用下载
在w2a模式下,可以通过落地页链接传递很多信息,丢失率极低,在android的app直投中,facebook是通过集成Google Play Install Referrer
来实现广告元数据的透传的。
android可以通过fb的sdk拿到Google Play Install Referrer
的数据如下:
url
utm_source=apps.facebook.com
&utm_campaign=fb4a
&utm_content=%7B%22app%22%117412253453453%2C%22t%22%3A1723086075%2C%22source%22%3A%7B%22data%22%3A%22767b16f17139f42928f097aa5dcd0c682584aca809fa42a795ac3b1f9537a5eb375587ff8dfe9c53f26465c6ec1c06d665eb365acdd4de51338b8c68dc65bb52e1a57bd74f17c46f8ab6e45a801ae9a6d60b8f434817044ab5c1e8c45a4de86747e1e165c9bcb0bc354dc0571fefecaeabdc343eb26a81aa65b70455620004b54654f985f625829efc87eba3470d74c174befa3e5267b441418854ced55efe89335af17816b49b3bbc890579abcfc83d4e71cbabd06d932e7832fb80d59c1379302d6e76226440c204c1e0ba8c8d2a612ba648f0f13814fef9e347c5eb562dafb5c0e668ee2b6efa4eb0290f3b1901f4f2c469852728f53fe824774a708d749dee56241a0fc46c15e64dba20f3c1132d0318adb66c68dcc5569131cccdcd7b2a2dc6a2bc0eb0eda2bd2a8ac3c6a15ea88163aac41e2e7167b764da6f7302a786fda4c7fe768003242f91c95c2e1a8a24a5a99f155f87d546793e89a7b254222f5216e0504db1880aa69515043d584ba4056bdf93159b0a433f234150653da8bc293b0dcd7d495946fe170a314348390dbbd79a69d8d8dfe58d44d3e3291d3f913ad4e7caff375b114580430745aee778ef9078861a87868f7d99d6f8c788ae%22%2C%22nonce%22%3A%22824936fdaa16b355c76c0b1d%22%7D%7D
json
utm_content中的data信息就是广告的元数据信息,那这个如何去解呢?
{"app":117412253453453,
"t":1723086075,
"source":{
"data":"767b16f17139f42928f097aa5dcd0c682584aca809fa42a795ac3b1f9537a5eb375587ff8dfe9c53f26465c6ec1c06d665eb365acdd4de51338b8c68dc65bb52e1a57bd74f17c46f8ab6e45a801ae9a6d60b8f434817044ab5c1e8c45a4de86747e1e165c9bcb0bc354dc0571fefecaeabdc343eb26a81aa65b70455620004b54654f985f625829efc87eba3470d74c174befa3e5267b441418854ced55efe89335af17816b49b3bbc890579abcfc83d4e71cbabd06d932e7832fb80d59c1379302d6e76226440c204c1e0ba8c8d2a612ba648f0f13814fef9e347c5eb562dafb5c0e668ee2b6efa4eb0290f3b1901f4f2c469852728f53fe824774a708d749dee56241a0fc46c15e64dba20f3c1132d0318adb66c68dcc5569131cccdcd7b2a2dc6a2bc0eb0eda2bd2a8ac3c6a15ea88163aac41e2e7167b764da6f7302a786fda4c7fe768003242f91c95c2e1a8a24a5a99f155f87d546793e89a7b254222f5216e0504db1880aa69515043d584ba4056bdf93159b0a433f234150653da8bc293b0dcd7d495946fe170a314348390dbbd79a69d8d8dfe58d44d3e3291d3f913ad4e7caff375b114580430745aee778ef9078861a87868f7d99d6f8c788ae"
,"nonce":"824936fdaa16b355c76c0b1d"
}
}
需要使用facebook应用中的安装引荐来源解密密钥
那如何来解密呢?
jsx
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.engines.AESFastEngine;
import org.bouncycastle.crypto.modes.GCMBlockCipher;
import org.bouncycastle.crypto.params.AEADParameters;
import org.bouncycastle.crypto.params.KeyParameter;
import org.dromara.hutool.core.codec.binary.HexUtil;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.SecureRandom;
import java.util.Base64;
public class AESGCMExample {
private static final int GCM_NONCE_LENGTH = 12; // GCM 计数器大小
private static final int GCM_TAG_LENGTH = 16; // GCM 验证标签大小 (128位)
public static void main(String[] args) throws Exception {
// 密钥(这个是转过hex的,所以要先转回来)
String keyStr= "使用自己的安装引荐来源解密密钥";
byte[] decode = HexUtil.decode(keyStr);
// 随机数
String nonce ="824936fdaa16b355c76c0b1d";
SecretKeySpec key = new SecretKeySpec(decode, "AES");// 将 key 转换为SecretKey
// 密文
String encryptedText = "767b16f17139f42928f097aa5dcd0c682584aca809fa42a795ac3b1f9537a5eb375587ff8dfe9c53f26465c6ec1c06d665eb365acdd4de51338b8c68dc65bb52e1a57bd74f17c46f8ab6e45a801ae9a6d60b8f434817044ab5c1e8c45a4de86747e1e165c9bcb0bc354dc0571fefecaeabdc343eb26a81aa65b70455620004b54654f985f625829efc87eba3470d74c174befa3e5267b441418854ced55efe89335af17816b49b3bbc890579abcfc83d4e71cbabd06d932e7832fb80d59c1379302d6e76226440c204c1e0ba8c8d2a612ba648f0f13814fef9e347c5eb562dafb5c0e668ee2b6efa4eb0290f3b1901f4f2c469852728f53fe824774a708d749dee56241a0fc46c15e64dba20f3c1132d0318adb66c68dcc5569131cccdcd7b2a2dc6a2bc0eb0eda2bd2a8ac3c6a15ea88163aac41e2e7167b764da6f7302a786fda4c7fe768003242f91c95c2e1a8a24a5a99f155f87d546793e89a7b254222f5216e0504db1880aa69515043d584ba4056bdf93159b0a433f234150653da8bc293b0dcd7d495946fe170a314348390dbbd79a69d8d8dfe58d44d3e3291d3f913ad4e7caff375b114580430745aee778ef9078861a87868f7d99d6f8c788ae";
byte[] decrypt = decrypt(HexUtil.decode(encryptedText), HexUtil.decode(keyStr), HexUtil.decode(nonce));
System.out.println("Decrypted Text: " + new String(decrypt));
}
public static byte[] decrypt(byte[] EncryptedText, byte[] key, byte[] iv) {
try {
GCMBlockCipher cipher = new GCMBlockCipher(new AESFastEngine());
AEADParameters parameters = new AEADParameters(new KeyParameter(key), MacBitSize, iv, null);
cipher.init(false, parameters);
byte[] plainBytes = new byte[cipher.getOutputSize(EncryptedText.length)];
int retLen = cipher.processBytes(EncryptedText, 0, EncryptedText.length, plainBytes, 0);
cipher.doFinal(plainBytes, retLen);
return plainBytes;
} catch (IllegalArgumentException | IllegalStateException | DataLengthException | InvalidCipherTextException ex) {
System.out.println(ex.getMessage());
}
return null;
}
}
解密出来的内容
json
{
"ad_id": 广告id,
"ad_objective_name": "推广目标",
"adgroup_id": 广告组id,
"adgroup_name": "广告组名称",
"campaign_id": 推广系列id,
"campaign_name": "推广系列名称",
"campaign_group_id": 未知,
"campaign_group_name": "未知",
"account_id": 广告主账户id,
"is_instagram": false,
"is_an": false,
"publisher_platform": "facebook",
"platform_position": null
}
官方只提供了php和python的写法,我这里是写的是在java服务端的解法
关于Facebook App Ads Referral URL
https://developers.facebook.com/docs/app-ads/install-referrer/
facebook应用管理地址