简体   繁体   English

php-ga:如何识别自然流量?

[英]php-ga: How to identify organic traffic?

I'm doing all my Google Analytics server side, but GA is only tracking direct or referrals, and I don't know how to track organic. 我正在所有Google Analytics(分析)服务器端工作,但GA仅跟踪直接或引荐,并且我不知道如何跟踪自然搜索。 This is a pice of code that gets either direct or referral: 这是直接或引荐代码的一部分:

              //Campaign is used for the referrals
              //If not in session and there is a referrer, create campaign from referrer 
              //and add it to the tracker and to session.
               if (!isset($_SESSION['campaign'])) {
                        if (isset($_SERVER['HTTP_REFERER']) && 
                                strpos($_SERVER['HTTP_REFERER'], parse_url($this->config['url']['base'], PHP_URL_HOST)) === FALSE) {
                                $campaign = GoogleAnalytics\Campaign::createFromReferrer($_SERVER['HTTP_REFERER']);
                                $this->tracker->setCampaign($campaign);
                                $_SESSION['campaign'] = serialize($campaign);
                        }
                } else {
                        //If already in session, add it to the tracker
                        $this->tracker->setCampaign(unserialize($_SESSION['campaign']));
                }

The above basically analyzes the referer; 以上是对引荐来源网址的基本分析; if from another source, creates a referral, if not it doesn't. 如果来自其他来源,则创建引荐,否则创建引荐。 Then it is stored in the session if there was a referral. 然后,如果存在引用,它将存储在会话中。

Now, how would I identify organic sources? 现在,我将如何识别有机来源? I was thinking on making a table of possible organic sources, is this how Google does it? 我当时在考虑制作可能的有机来源表格,这是Google的做法吗? Something like: 就像是:

protected $organic_sources = array('www.google.com', 'www.yahoo.com')

Then I would check the source in there before creating the campaign, if in array I would create it as an organic campaign. 然后,我将在创建广告系列之前检查其中的源,如果在数组中我会将其创建为有机广告系列。 Is this an optimal solution? 这是最佳解决方案吗? Any thoughts on how to identify organic traffic? 关于如何识别自然流量有何想法?

Yes, that's how Google does it. 是的,这就是Google的做法。 I created a small function to identify organic traffic. 我创建了一个小功能来识别自然流量。 It goes like this: 它是这样的:

        /*
         * Organic sources
         */
        protected $organic_sources = array('www.google' => array('q='),
                                           'daum.net/' => array('q='),
                                           'eniro.se/' => array('search_word=', 'hitta:'),
                                           'naver.com/' => array('query='),
                                           'yahoo.com/' => array('p='),
                                           'msn.com/' => array('q='),
                                           'bing.com/' => array('q='),
                                           'aol.com/' => array('query=', 'encquery='),
                                           'lycos.com/' => array('query='),
                                           'ask.com/' => array('q='),
                                           'altavista.com/' => array('q='),
                                           'search.netscape.com/' => array('query='),
                                           'cnn.com/SEARCH/' => array('query='),
                                           'about.com/' => array('terms='),
                                           'mamma.com/' => array('query='),
                                           'alltheweb.com/' => array('q='),
                                           'voila.fr/' => array('rdata='),
                                           'search.virgilio.it/' => array('qs='),
                                           'baidu.com/' => array('wd='),
                                           'alice.com/' => array('qs='),
                                           'yandex.com/' => array('text='),
                                           'najdi.org.mk/' => array('q='),
                                           'aol.com/' => array('q='),
                                           'mamma.com/' => array('query='),
                                           'seznam.cz/' => array('q='),
                                           'search.com/' => array('q='),
                                           'wp.pl/' => array('szukai='),
                                           'online.onetcenter.org/' => array('qt='),
                                           'szukacz.pl/' => array('q='),
                                           'yam.com/' => array('k='),
                                           'pchome.com/' => array('q='),
                                           'kvasir.no/' => array('q='),
                                           'sesam.no/' => array('q='),
                                           'ozu.es/' => array('q='),
                                           'terra.com/' => array('query='),
                                           'mynet.com/' => array('q='),
                                           'ekolay.net/' => array('q='),
                                           'rambler.ru/' => array('words=')
                                     );

Just put the above in your class, and add this function: 只需将以上内容放入您的课程,然后添加以下功能:

        /*
         * Check if source is organic
         * 
         * @param string $referrer The referrer page
         * 
         * @return true if organic, false if not
         */
        public function isTrafficOrganic($referrer) {
                //Go through the organic sources
                foreach($this->organic_sources as $searchEngine => $queries) {
                    //If referrer is part of the search engine...
                    if (strpos($referrer, $searchEngine) !== false) {
                            //Check if query is also there
                            foreach ($queries as $query) {
                                    if (strpos($referrer, $query) !== false) {
                                            //If there, traffic is organic
                                            return true;
                                    }
                            }
                    }
                }

                return false;
        }

You can then just call the function above by passing $_SERVER['HTTP_REFERER'] as param. 然后,您可以通过传递$_SERVER['HTTP_REFERER']作为参数来调用上面的函数。 Hope it's useful for someone. 希望对某人有用。

is this how Google does it 这是Google的做法吗

Basically yes - as far as GA is concerned an organic search visits is a referer from a known (by url) search engine plus a search parameter (to grab the search keyword) but without utm- or glcid-parameters (which would turn the referer into a campaign url). 基本上是-就GA而言,自然搜索访问是来自已知(按url)搜索引擎的引荐来源,加上搜索参数(以获取搜索关键字),但没有utm或glcid参数(这会使引荐来源进入广告系列网址)。 In client-side GA you can even add your own set of search engines, so I'd say that's the way it should work for the server side, too. 在客户端GA中,您甚至可以添加自己的搜索引擎集,因此我想这也是它在服务器端也应起作用的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM