使用谷歌分析的低端移动设备自定义变量(没有javascript)

时间:2021-12-03 15:12:33

I'm working on the Mxit platform & would like to create and capture some custom variables to store in Google Analytics.

我正在开发Mxit平台&想要创建并捕获一些自定义变量来存储在谷歌Analytics中。

With Mxit portals, it's not the usual communication between browser & web server. It's phone app, mxit server, web server. Mxit sits in the middle, which means we can’t directly capture user specific info.

对于Mxit门户,它不是浏览器和web服务器之间通常的通信。它是电话应用,mxit服务器,web服务器。Mxit位于中间,这意味着我们不能直接捕获特定用户的信息。

Mxit does however set custom headers with additional user info, which can be captured for Analytics via custom variables.

Mxit使用附加的用户信息设置自定义头信息,这些信息可以通过自定义变量进行分析。

We can't make use of javascript, so I’ve installed the Analytics for mobile php script, which creates and appends data to the gif image.

我们不能使用javascript,所以我安装了移动php脚本的分析,它创建并添加数据到gif图像。

I've set the custom variables on a normal website via javascript and using GA debug I copied the utme parameter and added it to the GA for mobile php code to append to manually append to the gif query string.

我通过javascript在普通网站上设置了自定义变量,并使用GA debug复制了utme参数,并将其添加到GA for mobile php代码中,以便将其附加到gif查询字符串中。

Here's a quick, over simplified example:

这里有一个简单的例子:

The custom values I'd like to set.

我想要设置的自定义值。

$id = $headers['mxitID'];
$country = $headers['country'];
$gender = $headers['gender'];
$age = $headers['age'];

and here I'm appending to the gif query string

这里我将附加到gif查询字符串

&utme=8(MxitID*Country*Gender*Age)9($id*$country*$gender*$age)11(1*1*1*1)

The way I understand it, 8() represents the custom variable names, 9() represents the custom variable values and 11() represents the scope.

按照我的理解,8()表示自定义变量名,9()表示自定义变量值,11()表示范围。

It's been 2 days now, and there is still no custom variable information in Google Analytics.

到现在已经2天了,谷歌分析中仍然没有自定义变量信息。

I'm checking Visitors > Custom Variables

我正在检查访问者>自定义变量

Any help would be appreciated.

如有任何帮助,我们将不胜感激。

2 个解决方案

#1


1  

Google has a server-side solution just for this issue. You can find the code here: https://developers.google.com/analytics/devguides/collection/other/mobileWebsites

谷歌有一个针对这个问题的服务器端解决方案。您可以在这里找到代码:https://developers.google.com/analytics/devguides/collection/other/mobilewebsite

Here's an implementation of that library

这里是该库的实现。

<?php
    class GoogleAnalytics {
        const ACCOUNT = "ACCOUNT ID GOES HERE";
        const PIXEL = "/ga.php";

        public static function getImageUrl() {
            $url .= self::PIXEL . '?';
            $url .= 'utmac=' . self::ACCOUNT;
            $url .= '&utmn=' . rand(0, 0x7fffffff);

            $referer = !empty($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : '-';
            $url .= '&utmr=' . urlencode($referer);

            if (!empty($_SERVER["REQUEST_URI"])) {
                $url .= "&utmp=" . urlencode($_SERVER["REQUEST_URI"]);
            }

            $url .= '&guid=ON';

            return str_replace('&', '&amp;', $url);
        }
    }
?>

And then in your view you do:

在你看来

<img src="<?php echo GoogleAnalytics::getImageUrl() ?>" />

#2


0  

I wrote some code for this.

我为此写了一些代码。

You can modify it as you wish. :{D

您可以根据需要修改它。:{ D

https://github.com/WillemLabu/ga-collection

https://github.com/WillemLabu/ga-collection

#1


1  

Google has a server-side solution just for this issue. You can find the code here: https://developers.google.com/analytics/devguides/collection/other/mobileWebsites

谷歌有一个针对这个问题的服务器端解决方案。您可以在这里找到代码:https://developers.google.com/analytics/devguides/collection/other/mobilewebsite

Here's an implementation of that library

这里是该库的实现。

<?php
    class GoogleAnalytics {
        const ACCOUNT = "ACCOUNT ID GOES HERE";
        const PIXEL = "/ga.php";

        public static function getImageUrl() {
            $url .= self::PIXEL . '?';
            $url .= 'utmac=' . self::ACCOUNT;
            $url .= '&utmn=' . rand(0, 0x7fffffff);

            $referer = !empty($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : '-';
            $url .= '&utmr=' . urlencode($referer);

            if (!empty($_SERVER["REQUEST_URI"])) {
                $url .= "&utmp=" . urlencode($_SERVER["REQUEST_URI"]);
            }

            $url .= '&guid=ON';

            return str_replace('&', '&amp;', $url);
        }
    }
?>

And then in your view you do:

在你看来

<img src="<?php echo GoogleAnalytics::getImageUrl() ?>" />

#2


0  

I wrote some code for this.

我为此写了一些代码。

You can modify it as you wish. :{D

您可以根据需要修改它。:{ D

https://github.com/WillemLabu/ga-collection

https://github.com/WillemLabu/ga-collection