Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Example: setcookie and increment visitCount #3

Open
mahal opened this issue Oct 21, 2013 · 0 comments
Open

Code Example: setcookie and increment visitCount #3

mahal opened this issue Oct 21, 2013 · 0 comments

Comments

@mahal
Copy link

mahal commented Oct 21, 2013

it's a great library, just implemented it for our xml-newsfeed transported to a Mac App.

Biggest step was to implement the returning visitor count.

Now this is either a feature request for php-ga or for it's documentation:

Why would I have to do the increment of returning visits in my code? Why isn't this done inside tracker?

Now:
$isNewVisitor = true;
if ($_COOKIE['__utma']) {
$visitor->fromUtma($_COOKIE['__utma']);
$isNewVisitor = false;
}

if($isNewVisitor) {
    // all defaults are set when Visitor is inited
    // dont know how to get account hash from tracker...
    // $utmaContent = array( '217597461', $visitor->getUniqueId(), $visitor->getFirstVisitTime()->getTimeStamp(), $visitor->getPreviousVisitTime()->getTimeStamp(), $visitor->getCurrentVisitTime()->getTimeStamp(), $visitor->getVisitCount());
} else {
    $visitor->setVisitCount( $visitor->getVisitCount() + 1);
}

$utmaContent = array( '217597461', $visitor->getUniqueId(), $visitor->getFirstVisitTime()->getTimeStamp(), $visitor->getPreviousVisitTime()->getTimeStamp(), $visitor->getCurrentVisitTime()->getTimeStamp(), $visitor->getVisitCount());
$utmaContent = implode('.', $utmaContent);

$cookieSet = setcookie('__utma', $utmaContent, strtotime('+2 years'));

New:

  • a wrapper for setcookie can be called somehow thru Tracker or so
  • increment for pageview can be done with php-ga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant