php-ga:如何识别有机流量? [英] php-ga: How to identify organic traffic?

查看:102
本文介绍了php-ga:如何识别有机流量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做我所有的Google Analytics服务器端,但GA只跟踪直接或转介,我不知道如何跟踪有机。这是一个可以直接获取或引荐的代码片段:

  // Campaign用于引荐
/ /如果不在会话中,并且有推荐人,请从推荐人
//创建广告系列,然后将其添加到跟踪器和会话中。
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 {
//如果已经在session中,将它添加到跟踪器
$ this-> tracker-> setCampaign(unserialize($ _ SESSION ['campaign ]));
}

以上主要分析了referer;如果来自其他来源,则创建推荐,如果不是,则不推荐。然后,如果有推介,它将存储在会话中。



现在,我将如何识别有机来源?我正在考虑制作一个可能的有机来源的表格,谷歌是如何做到的?例如:

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

然后我会在创建广告系列之前检查其中的来源,如果在数组中,我会将其创建为有机运动。这是最佳解决方案吗?有关如何识别有机流量的任何想法?解决方案

是的,Google就是这么做的。我创建了一个小功能来识别有机流量。它是这样的:

  / * 
*有机来源
* /
保护$ organic_sources = array('www.google'=> array('q ='),
'daum.net/'=> array('q ='),
'eniro.se/ '=>数组('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.c om /'=>数组('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 =')
);

只需将上面的代码添加到您的课程中,然后添加以下函数:

  / * 
*检查源代码是否为有机
*
* @param string $ referrer引用者页面
*
* @return如果有机的话返回true,否则返回false
* /
public function isTrafficOrganic($ referrer){
//通过有机源
foreach $ this-> organic_sources as $ searchEngine => $ queries){
//如果referrer是搜索引擎的一部分...
if(strpos($ referrer,$ searchEngine)!== false){
//检查查询是否也存在
foreach($ queries as $ query){
if(strpos($ referrer,$ query)!== false){
//如果有,流量是有机
返回true;
}
}
}
}

return false;
}

然后您可以通过传递 $ _SERVER ['HTTP_REFERER'] 作为参数。希望它对某人有用。


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. 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? 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. 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. Hope it's useful for someone.

这篇关于php-ga:如何识别有机流量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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