简体   繁体   中英

Serverside Google Analytics without Zend - how?

I'm using a basic URL shortening script for one of my sites so that I can manage the URLs internally (and have less trailing characters on the urls). It's working well, but I'd like to be able to use Google Analytics to track the clicks.

I've found this: http://code.google.com/p/serversidegoogleanalytics/ which seems to achieve this using events, but I'm not using Zend. It mentions using curl to customise it, but without any knowledge of curl, would it simply be a case of amending this function from within the class:

public function getHttpClient () {
        if(!$this->httpClient instanceof Zend_Http_Client) {
            include_once("Zend/Http/Client.php");
            $this->httpClient = new Zend_Http_Client();
            $this->httpClient->setConfig(array(
                'maxredirects' => 1,
                'timeout'      => 4
            ));
            $this->httpClient->setHeaders('Referer', "http://" . self::$trackingDomain . "/");
            $this->httpClient->setHeaders("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729)");
            $this->httpClient->setCookieJar();
        }
        return $this->httpClient;
    }

You should be able to convert that to curl quite easily.

Curl is basically.

  1. get a curl handler
  2. configure the request through the handler
  3. do the request and grab the result if you need

Check out the examples page, it's pretty simple

http://au.php.net/manual/en/curl.examples-basic.php

EDIT: there's even examples of Analytics with curl on google. .

http://www.electrictoolbox.com/google-analytics-login-php-curl-username-password/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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