如何使用PHP在重定向页面上使用Google Analytics(分析)进行跟踪? [英] How to track with Google Analytics on a redirection page with PHP?

查看:63
本文介绍了如何使用PHP在重定向页面上使用Google Analytics(分析)进行跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我想跟踪谁点击了与GA相关的特定链接.

I have a website where I want to track who has clicked on specific links with GA.

假设我有此页面:/index.php?id=32

Let's say I have this page: /index.php?id=32

在此页面上,我基于ID变量(在本例中为32)运行一些查询,然后从数据库中获取32 id项的URL来重定向访问者.

On this page I run some query based on the ID variable (in this case: 32), and I get the URL of the 32 id item from the Database to redirect the visitor.

我正在使用PHP函数:header('Location: http://www.example.com ');.在重定向用户之前,我希望Google捕获访问者的信息,然后才重定向到所需的网页.

I'm using a PHP function: header('Location: http://www.example.com');. Before I'm redirecting the user, I want Google to capture the visitor's information and only then redirect to the desired webpage.

我尝试在重定向之前粘贴GA代码并回显它,但是它不起作用.使用GA如何跟踪此类网页?

I have tried to paste the GA code and ECHO it just before the redirection, however it did not work. How is it possible to track these kind of pages with GA?

推荐答案

一般来讲

如果您的页面使用重定向,则重定向页面将成为着陆页的引荐来源网址.例如,如果您更改了网站该index.html现在重定向到home.html,然后index.html变为home.html的引荐来源网址.如果有人通过Google到达您的网站首先将它们发送到index.html的搜索,您将没有任何数据关于Google搜索.

If your page uses redirects, the redirecting page becomes the landing page's referrer. For example, if you've changed your site so that index.html now redirects to home.html, then index.html becomes the referrer for home.html. If someone reached your site via a Google search that sent them first to index.html, you won't have any data regarding the Google search.

因此,您应该放置Google Analytics(分析)跟踪重定向页面以及登录页面上的代码.这条路,重定向页面将捕获实际的引荐来源信息您的报告.

For this reason, you should place the Google Analytics tracking code on the redirecting page as well as on the landing page. This way, the redirecting page will capture the actual referrer information for your reports.

请注意,某些浏览器实际上可能会在JavaScript之前重定向可以从代码中调用.

Note, some browsers may actually redirect before the JavaScript call from the code can be made.

(请参见 https://support.google.com/analytics/answer/1009614?hl = zh_CN )

由于PHP是在使用任何Javascript之前呈现并执行的,因此Google Analytics(分析)跟踪器没有机会将数据发送到其服务器.

Since PHP is rendered and executed before any Javascript, Google Analytics tracker has no chance to send data to its server.


考虑到您无法跟踪PHP重定向页面,有很多可能的选择:

Considering that you cannot track a PHP redirection page, there are a number of possible alternatives:

  • JavaScript重定向: https://stackoverflow.com/a/4745622/1672895
    • window.location ="http://www.yoururl.com";
    • 元刷新: https://stackoverflow.com/a/8692559/1672895
      • <元http-equiv =刷新" content ="5; url = http://example.com/">
      • 虚拟页面跟踪: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
        • ga('send','pageview','/index.php?id=32');
        • 广告系列跟踪(在这种情况下,我个人不会使用此方法.)
          • /products.php?utm_source=index&utm_medium=redirection-page&utm_campaign=32

          在进入PHP重定向页面之前,列表的最后两项是在初始页面上的各个链接上实现的.

          The last two items in the list are implemented on the individual links on the initial page before you get on the PHP redirection page.

          这篇关于如何使用PHP在重定向页面上使用Google Analytics(分析)进行跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆