![](/img/trans.png)
[英]GA Conversions link transaction to client id theiconic/php-ga-measurement-protocol
[英]PHP problems with Google Analytics E-commerce: theiconic/php-ga-measurement-protocol
我正在使用theiconic / php-ga-measurement-protocol程序包,並已按照自述文件中所述的確切步驟進行操作,但是由於我不太了解的原因,有一半的信息未顯示在Google Analytics(分析)中。
我正在使用以下代碼:
use TheIconic\Tracking\GoogleAnalytics\Analytics;
$trackingID = 'xxxxxxx';
$order = 'obviously an object';
$deal = 'object';
$analytics = new Analytics();
// the Client ID just won't do anything
$analytics->setProtocolVersion('1')
->setClientId($order->gaClientID)
->setTrackingId($trackingID);
// this part works just fine
$analytics->setTransactionId($transactionID)
->setRevenue($order->getTotalPrice(false))
->setTax($order->getTaxCost())
->sendTransaction();
// here it's as if nothing happens
// Yes, it does loop over all the orderRules but it does not show up in Google Analytics
foreach ($order->getOrderRules() as $orderRule) {
$analytics->setTransactionId($transactionID)
->setItemName($deal->name)
->setItemCode($order->dealID)
->setItemCategory($deal->getDealCategoryName())
->setItemPrice($orderRule->getPrice())
->sendItem();
}
我將使用此JavaScript的ClientID保存到隱藏的輸入中:
ga.getAll()[0].get('clientId')
所以我的問題基本上是:
我有什么要忘的嗎? 我有好幾個人在看它,卻無法找出問題出在哪里。
我會怎么做:
增強型電子商務 :用用於增強型電子商務的代碼替換舊的電子商務代碼 。 原因:新(增強)與舊版本向后兼容,並且具有許多其他功能,因此使用舊電子商務的得分為0。 原因2:增強的電子商務實現看起來“更干凈”,因為所有數據最后都->sendEvent();
一次就發送了( ->sendEvent();
),而舊的電子商務首先發送了交易(- > sendTransaction();),然后再使用單獨的匹配項( ->sendItem();
)添加產品。
偵錯 :啟用偵錯模式以找出是否/為什么您的匹配被API拒絕。
通過增強型電子商務,它應該類似於:
$analytics->setDebug(true)
->setEventCategory('Checkout')
->setEventAction('Purchase')
->sendEvent();
$debugResponse = $response->getDebugResponse();
print_r($debugResponse);
而且您應該從如下所示的API獲得調試 :
{
"hitParsingResult": [
{
"valid": false,
"hit": "GET /debug/collect?tid=fake\u0026v=1 HTTP/1.1",
"parserMessage": [
{
"messageType": "ERROR",
"description": "The value provided for parameter 'tid' is invalid. Please see ... for details.",
"parameter": "tid"
},
我再次嘗試了增強型電子商務。 我之前也做過,但是這次啟用了調試功能。 如hitPersingResult [0] ['hit']所示,可以正確發送客戶端ID。 但在Google Analytics(分析)中仍然沒有任何內容。
同樣,我們沒有達到極限。 我從字面上復制了粘貼示例,這是我的回應:
Array
(
[hitParsingResult] => Array
(
[0] => Array
(
[valid] => 1
[parserMessage] => Array
(
)
[hit] => /debug/collect?v=1&tid=UA-xxxxxxxx-11&cid=161460xxxx.xxxx180000&uid=161460xxxx.xxxx180000&ti=1802.48511-1518713633&ta=test%20affiliation&tr=206.95&tt=3.4623966942149&ts=0&pa=purchase&ec=Checkout&ea=Purchase&t=event&pr1id=2033&pr1nm=xxxxx&pr1br=brand&pr1ca=xxxxxx&pr1pr=xxx&pr1qt=1
)
)
[parserMessage] => Array
(
[0] => Array
(
[messageType] => INFO
[description] => Found 1 hit in the request.
)
)
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.