【问题标题】:Google Analytics Custom Metrics not showing up谷歌分析自定义指标未显示
【发布时间】:2017-05-26 10:05:04
【问题描述】:

我想将交易的产品利润推送到 Google Analytics。 有了这个,我想生成一个报告,我可以在其中查看产品总收入以及已订购的每种产品的利润。

我正在使用此 api 将自定义指标推送到分析 (Measurement protocol api)

我在分析中做了几个自定义指标,例如:

  • Productsprofit(范围命中,小数)
  • Productsprofit2(范围产品,十进制)

我已经用谷歌搜索了好几次,我认为我需要使用 Scope Hit 进行这种类型的跟踪,对吗?

我已使用 api 将具有正确索引的指标推送到 Analytics

$analytics->setTransactionId('test'.$orderId)
        ->setAffiliation('Testshop')
        ->setRevenue(number_format($orderTotalPrice,2,'.',''))
        ->setTax(number_format($taxTotal,2,'.',''))
        ->setShipping(number_format($shippingTotal,2,'.',''))
        ->setCouponCode('');

    foreach($orderInfo['orderDetails'] as $orderDetail) {

        // Include a product, only required fields are SKU and Name
        $productData1 = [
            'sku' => $orderDetail['model'],
            'name' => $orderDetail['name'],
            'brand' => '',
            'category' => '',
            'variant' => '',
            'price' => number_format($orderDetail['price'], 2, '.', ''),
            'quantity' => $orderDetail['aantal'],
            'coupon_code' => '',
            'position' => 0,
            'custom_metric_3'=>50.45, //<-- test data (Hit)
            'custom_metric_4'=>15.50 //<-- test data (Product)
        ];

        $analytics->addProduct($productData1);
    }
// Don't forget to set the product action, in this case to PURCHASE
    $analytics->setProductActionToPurchase();

// Finally, you must send a hit, in this case we send an Event
    $analytics->setEventCategory('Checkout')
        ->setEventAction('Purchase')
        ->sendEvent();

我创建了一个自定义报告并将这些指标添加到我的报告中。但在我的报告中,这两个指标都为空。

有谁知道我做错了什么?或者什么可以解决我的问题?

提前致谢!

【问题讨论】:

标签: google-analytics analytics metric


【解决方案1】:

在您使用的 PHP 库中,自定义指标和维度根据范围以不同的方式设置,对于 Product 范围,您可以像以前一样使用产品数组,对于 Hit 范围,您使用 setCustomMetric 方法。在您的代码中,这看起来像:

$analytics->setTransactionId('test'.$orderId)
    ->setAffiliation('Testshop')
    ->setRevenue(number_format($orderTotalPrice,2,'.',''))
    ->setTax(number_format($taxTotal,2,'.',''))
    ->setShipping(number_format($shippingTotal,2,'.',''));

foreach($orderInfo['orderDetails'] as $orderDetail) {

    $productData1 = [
        'sku' => $orderDetail['model'],
        'name' => $orderDetail['name'],
        'brand' => 'the brand',
        'category' => 'test category',
        'variant' => 'variant x',
        'price' => number_format($orderDetail['price'], 2, '.', ''),
        'quantity' => $orderDetail['qty'],
        'coupon_code' => 'coupon used',
        'custom_metric_4' => 15.50,
    ];

    $analytics->addProduct($productData1);
}

$analytics->setProductActionToPurchase();

$analytics->setCustomMetric(50.45, 3);

$analytics->setEventCategory('Checkout')
    ->setEventAction('Purchase')
    ->sendEvent();

在发送命中之前,请注意对 $analytics-&gt;setCustomMetric(50.45, 3); 的调用。这应该发送正确的数据,剩下的就是在 Google Analytics 中创建或查看正确的报告。

【讨论】:

    猜你喜欢
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多