php开发腾讯广告api回传归因的流程(微信朋友圈、公众号、小程序)

目录

创建数据源

广告账号id

账号assess_token

转化归因(你需要回传什么事件的意思?)

clickid

资产分发


目前网上几乎没有文章说这个流程的问题,现在我来说说吧。

下面是我们投放的广告位置

先贴代码

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的接口地址,写你自己的。

https://developers.e.qq.com/oauth/authorize?client_id=123456&redirect_uri=https%3a%2f%2fblue-sea-697d.quartiers047.workers.dev%3a443%2fhttps%2fwww.example.com%3fpara1%3da%26para2%3db&state=&scope=ads_management&account_type=ACCOUNT_TYPE_QQ
 

这是我接受授权的回调地址代码:
 

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 的值

在你联调的时候,腾讯会给你带参数的:

https://www.xxxx.com?page_id=478&cre_id=3585589783&image=30771196662_33444725097&video=__video_component_id__&descrip=30771196662_32531588932_33444802375&wx_aid=46838749493&tid=46840693264&gdt_vid=wx0hntx73vhss4ty01&wx_traceid=wx0hntx73vhss4ty01&code=0815a3ll25E4Sf4ZV9ol2JcIzp15a3l6&state=STATE


这是我平台的落地页链接

里面就有gdt_vid,这个就是clickid

好了,参数都齐了,那么就发起回传吧


 

这个trace_id就是腾讯的日志id,在这里查看是否成功:

资产分发

如果归因还是不行,请检查是否开启了资产分发,步骤如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伟大的开源程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值