从perl脚本向google analytics发布度量
我需要从perl cron作业生成一个google分析事件 基于 发布到www.google-analytics.com/collect将接受这些指标 我试着用下面的代码发布指标,但我在谷歌分析实时页面上看不到它们从perl脚本向google analytics发布度量,perl,google-analytics,Perl,Google Analytics,我需要从perl cron作业生成一个google分析事件 基于 发布到www.google-analytics.com/collect将接受这些指标 我试着用下面的代码发布指标,但我在谷歌分析实时页面上看不到它们 use LWP::UserAgent; $ua=LWP::UserAgent->new; $ua->default_header("Content-type" => "application/x-rm-urlencoded"); my $response =
use LWP::UserAgent;
$ua=LWP::UserAgent->new;
$ua->default_header("Content-type" => "application/x-rm-urlencoded");
my $response = $ua->post("http://www.google-analytics.com/collect",
"v" => 1,
"tid" => "UA-XXXXXXXX-Y",
"cid" => 125,
"t" => "pageview",
"dh" => "Cron",
"dp" => "Cron.php",
"dt" => "CronTitle");
print $response->status_line;'
回答是“200 OK”,但我没有在谷歌分析网页上看到数据 我可以从php脚本发布分析,但无法从perl脚本发布分析 我解决了我的问题如下。 创建了一个实用程序php脚本,并从我的perl脚本中调用该php脚本。然后它成功了
<?php
$ec = $_GET['ec'];
$ea = $_GET['ea'];
$el = $_GET['el'];
$ev = $_GET['ev'];
// Send event tracking as well.
$url = 'http://www.google-analytics.com/collect';
$event_data = array(
'v' => '1',
'tid' => 'UA-XXXXXX-Y',
'cid' => $_SERVER["REMOTE_ADDR"],
't' => 'event',
'ec' => $ec,
'ea' => $ea,
'el' => $el,
'ev' => $ev);
$event_options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($event_data),
),
);
$event_context = stream_context_create($event_options);
$result = file_get_contents($url, false, $event_context);
echo "XXX";
?>
“dh”
参数不应该包括您的主机地址吗?e、 g.&dh=yourhostname.com
?您在实时视图中查看了吗?数据不会立即显示在标准报告中。@EikePierstorff是。我正在跟踪实时视图,但我没有看到Cron.php页面的页面视图数据。@Htaras re:您对我删除的“答案”的评论(我删除了它,因为我打算将其作为评论发布):如果您尝试将主机名添加到dh
,但在GA中仍然没有看到此指标,您是否能够捕获或记录您得到的响应?我想您的意思是上面提到的200 OK
,但是本手册中提到的其他问题是否适用?例如,环境中是否有代理服务器?