目录
目前网上几乎没有文章说这个流程的问题,现在我来说说吧。
下面是我们投放的广告位置
先贴代码
public static function tengXunAdCallBack($clickId, $action_type)
{
$apiUrl = 'https://api.e.qq.com/v3.0/user_actions/add';
$accessToken = 广告应用access_token;
$accountId = 替换为你的账户ID; // 替换为你的账户ID
$userActionSetId = 你的数据源ID; // 你的数据源ID
$nonce = bin2hex(random_bytes(16));
$actionTime = time();
$requestData = json_encode([
'account_id' => $accountId,
'user_action_set_id' => $userActionSetId,
'actions' => [
[
'action_time' => $actionTime,
'action_type' => $action_type,
'trace' => [
'click_id' => $clickId,
],
// 这个是你投放的域名,注意不要带参数。就域名到路由
'url' => 'baidu.com/xmly',
],
],
]);
$res = Curl::to($apiUrl)->withHeaders([
'Content-Type' => 'application/json',
'access-token' => $accessToken,
'timestamp' => $actionTime,
'nonce' => $nonce,
'cache-control' => 'no-cache',
])->withData($requestData)->post();
Log::info(__FUNCTION__, ['$res' => $res, '$requestData' => $requestData]);
}
下面我开始解释,那些参数是怎么获取的,先来数据源id
创建数据源
创建数据源,进入投放管理平台
创建数据源
这里有一个appid,这个appid是你创建广告转化归因填写的appid,文档如下:https://docs.qq.com/doc/DU01QTUVGY1VmV01K
通过文档看到,这是创建转化归因上报时候填写的appid,和数据源要一致
下面这个图片是采自文档中的
创建完之后,你就会得到数据源id
广告账号id
账号assess_token
腾讯文档:https://developers.e.qq.com/v3.0/pages/authorization_and_authentication
他是像微信那样的,回调一个code给你,然后你去拉accesstoken的
下面这链接的redirect_uri就是你的接受code的接口地址,写你自己的。
这是我接受授权的回调地址代码:
public function messageCallback(Request $request)
{
Log::info('腾讯api回传 回调地址(messageCallback)', [
'requestData' => $request->all(),
]);
// $all = $request->all();
try {
$authorization_code = $request->input('authorization_code');
$client_id = 看应用id;
$client_secret = 看应用密钥;
$req = [
'client_id' => $client_id,
'client_secret' => $client_secret,
'authorization_code' => $authorization_code,
'grant_type' => 'authorization_code',
'redirect_uri' => '和你填写的回调地址一致',
];
$res = Curl::to('https://api.e.qq.com/oauth/token')->withData($req)->asJson(true)->get();
if (!isset($res['data']) || !$res['data']) {
Log::error('腾讯广告授权失败', ['req' => $req, 'res' => $res]);
throw new \Exception('授权失败');
}
$key = 'tengxunguanggao_' . $client_id;
$redis = Redis::connection('redis2');
$cacheData = [
'access_token' => $res['data']['access_token'],
'appid' => $client_id,
'secert' => $client_secret,
'refresh_token' => $res['data']['refresh_token'],
'refresh_token_expires_in' => time() + 518400,
'expired_at' => time() + 475200,
];
$redis->hmset($key, $cacheData);
return response()->json([
'code' => 0,
'msg' => 'success',
], 200);
} catch (\Exception $e) {
Log::error('腾讯广告授权失败', [
'msg' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
]);
return response()->json([
'code' => 500,
'msg' => 'error',
], 500);
}
}
转化归因(你需要回传什么事件的意思?)
我创建了两个事件,那么就代表,等下回传给腾讯,就必须要有这两个事件才算一个成功归因
提交表单就是用户下单不支付这时候要回传这个事件
下单就是用户支付给钱了,回调告诉商家系统,这时候就要回传这个事件
clickid
文档:https://datanexus.qq.com/doc/develop/guider/interface/conversion/trackingcgi_api_web
这个id,对于腾讯广告非微信流量为URL中的参数 qz_gdt 的值,对于微信流量为 URL 中的参数 gdt_vid 的值
在你联调的时候,腾讯会给你带参数的:
里面就有gdt_vid,这个就是clickid
好了,参数都齐了,那么就发起回传吧
这个trace_id就是腾讯的日志id,在这里查看是否成功:
资产分发
如果归因还是不行,请检查是否开启了资产分发,步骤如下: