我有一个用 php 编写的 Web 服务,它是从安装在 PC 上的桌面应用程序调用的。 我想要注册调用网络服务上的函数的用户,为此我只想将点击发送到 Google Analytics。
PHP 中的网络服务:
<?php
require_once('lib/nusoap.php'); // basic include.. must go at the top
$SERVICE_NAMESPACE = "urn:Service"; // create a namespace to run under.
$server = new soap_server(); // the soap object from the include above.
// this has many input parameters but we only need two: the service name and the namespace
$server->configureWSDL('Service', $SERVICE_NAMESPACE);
$server->register('test',// method name
array('name' => 'xsd:string', 'name99' => 'xsd:string'),// input parameter called name.. and it's a string.
array('return' => 'xsd:string'),// output - one string is returned called "return"
$SERVICE_NAMESPACE,// namespace
$SERVICE_NAMESPACE . '#hello1',// soapaction
'rpc',// style.. remote procedure call
'encoded',// use of the call
'Nada interesante'// documentation for people who hook into your service.
);
function test($sName,$sName99)
{
return 'TEST ';
}
//This processes the request and returns a result.
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
我想要谷歌分析信息,为此我想集成以下脚本:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-89356985-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-89356985-1');
</script>
我不知道如何集成到测试功能中。我想知道用户何时调用测试函数。
非常感谢。
最佳答案
除非您的 PHP 脚本生成在浏览器中执行的 HTML 和 Javascript,否则您无法使用 Javascript 跟踪器。
但是您可以使用Measurement Protocol向 Google Analytics 进行服务器端调用。这基本上是一个端点,您可以在其中发送带有自定义值的预定义参数(通过任何可以进行 http 调用的方法),并且它们将在 Google Analytics 中注册。
关于php - 如何在 php web 服务中包含谷歌分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47345864/