简体   繁体   English

Google Analytics(分析)电子商务的PHP问题:theiconic / php-ga-measurement-protocol

[英]PHP problems with Google Analytics E-commerce: theiconic/php-ga-measurement-protocol

I'm using the theiconic/php-ga-measurement-protocol package and have followed the exact steps as described in the readme, but for reasons I don't quite understand, half of the info does not show up in Google Analytics. 我正在使用theiconic / php-ga-measurement-protocol程序包,并已按照自述文件中所述的确切步骤进行操作,但是由于我不太了解的原因,有一半的信息未显示在Google Analytics(分析)中。

I'm using the following code: 我正在使用以下代码:

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();
}

And I'm saving the ClientID with this JavaScript into a hidden input: 我将使用此JavaScript的ClientID保存到隐藏的输入中:

ga.getAll()[0].get('clientId')

So my issues are basically: 所以我的问题基本上是:

  • client ID does not work 客户编号无效
  • Items do not appear in Google Analytics Ecommerce 项目没有出现在Google Analytics(分析)电子商务中

Is there anything I am forgetting? 我有什么要忘的吗? I've had several people looking at it, not being able to find out where it's going wrong. 我有好几个人在看它,却无法找出问题出在哪里。

What I would do: 我会怎么做:

  • Enhanced e-commerce : replace your code which is for the old e-commerce with this code which is for enhanced e-commerce. 增强型电子商务 :用用于增强型电子商务的代码替换旧的电子商务代码 Reason: new (enhanced) is backward compatible with the old and has lots more features, so 0 point of using old e-commerce. 原因:新(增强)与旧版本向后兼容,并且具有许多其他功能,因此使用旧电子商务的得分为0。 Reason 2: the enhanced e-commerce implementation seems "cleaner" in the sense that all the data is sent with 1 single hit at the end ( ->sendEvent(); ), whereas the old e-commerce first sends the transaction (->sendTransaction();) then later the products with separate hits ( ->sendItem(); ). 原因2:增强的电子商务实现看起来“更干净”,因为所有数据最后都->sendEvent();一次就发送了( ->sendEvent(); ),而旧的电子商务首先发送了交易(- > sendTransaction();),然后再使用单独的匹配项( ->sendItem(); )添加产品。

  • Debug : enable debug mode to find out if/why your hits are being rejected by the API. 侦错 :启用侦错模式以找出是否/为什么您的匹配被API拒绝。

With enhanced e-commerce it should be something like: 通过增强型电子商务,它应该类似于:

$analytics->setDebug(true)
  ->setEventCategory('Checkout')
  ->setEventAction('Purchase')
  ->sendEvent();
$debugResponse = $response->getDebugResponse();
print_r($debugResponse);

And you should get debug from the API that will look like this: 而且您应该从如下所示的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"
        },
  • Filters: if your hits are not rejected by the API (once they are validated you have to remove the debug for them to be actually sent), I would look in GA to check if you don't have filters excluding your hits. 过滤器:如果您的匹配没有被API拒绝(一旦通过验证,则您必须删除调试才能将其实际发送),我会在GA中检查您是否没有排除匹配的过滤器。

  • Quotas : although unlikely, I would also check if you haven't reached the API limits hence why your data isn't being collected. 配额 :尽管不太可能,但我还会检查您是否尚未达到API限制,因此为什么不收集您的数据。

  • BONUS: User-ID : if people making purchases have created a user account on your website, use your database ID as User ID : it will be easier to implement (you don't have to reverse engineer the Client ID, use your database ID), and will track the same user regardless of the browser/device used (Client ID is linked to the Cookie, so will be different for each device/browser the user uses, your database ID will always be the same as long as people log in with the same account) 奖励:用户ID :如果进行购买的人已经在您的网站上创建了一个用户帐户,则将您的数据库ID用作User ID :实施起来会更容易(您不必对客户ID进行反向工程,也可以使用数据库ID ),并且无论使用什么浏览器/设备,它都将跟踪同一用户(客户端ID链接到Cookie,因此该用户使用的每台设备/浏览器都会有所不同,只要用户登录,您的数据库ID就会始终相同在同一个帐户中)

I've tried the enhanced e-commerce again. 我再次尝试了增强型电子商务。 I've done that before as well, but this time with the debug function on. 我之前也做过,但是这次启用了调试功能。 The client ID gets send properly as seen in hitPersingResult[0]['hit']. 如hitPersingResult [0] ['hit']所示,可以正确发送客户端ID。 But still nothing appears in google Analytics. 但在Google Analytics(分析)中仍然没有任何内容。

Also we're not hitting the limits. 同样,我们没有达到极限。 I've literally copy pasted the example and this is my response: 我从字面上复制了粘贴示例,这是我的回应:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM