Link to home
Start Free TrialLog in
Avatar of roger v
roger vFlag for United States of America

asked on

How to monitor specific webpage through Google analytics API?

Hello experts,

I'm trying to accomplish something that may not have been attempted before. My requirements:

      1. Integrate with Google Analytics API, using coldfusion or php (cfhttp?)
      2. Check for a specific page (mypage.html) in my website. The check is to see if this specific page (mypage.html) has been fired in the past 15 minutes.
      3. If it has been fired in past 15 minutes, do nothing.
      4. If it hasn't been fired in past 15 minutes, then send out an email to admin.
      
      The problem I'm having is trying to figure out how to do the integration with google analytics api, and then check for that specific page, and if it has been fired in past 15 mins. Does anyone know if there is a free tool that already does this? Or could someone point me to a CF or php solutions that is already available? If there is nothing out there, how do I go about building this app?
      
      Thanks,

roger
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What is the role of Google Analytics in this application?  My guess would be that you can use a CRON job, fired every 15 minutes, to check a database or filesystem entry.  When the entry goes stale, you send the message to the admin.
Avatar of roger v

ASKER

@Ray Paseur:

GA tracks all the site stats. Anytime an order is successfully processed, mypage.html is fired. I need to check every 15 mins if the mypage.html has been fired at all, and then send out email accordingly.
Reg. the cron job -- would this be written in php? How would I integrate this with GA api? thanks,
The cron job could be written in PHP. (IIRC, it's called a "scheduled task" if you're on a Window server)

 I don't actually see a role for Google Analytics in the application, which is why I was asking how you see it fitting in.  I think this is a totally self-contained application.  GA can observe, but not intervene in the process.
Avatar of roger v

ASKER

@Ray,

GA is where I can track if a particular web page in my web site is fired or not. GA tracks stats for all my web pages, so I can check if a particular page has been successfully loaded or not for a particular time period. Not sure what you mean by 'GA can observe' -- I have to integrate with GA in order to get my web page statistics. Does this make sense or it's still unclear?

thanks,
roger
GA runs JavaScript that is loaded from Google's engines.  The JavaScript runs on the client browser and sends information back to Google, where it is aggregated and used to give you the GA reports.  Please correct me if I'm misunderstanding, but I think you want contemporaneous notice when a fifteen minute period elapses without access to a particular web page.  There is no ability for Google (or any other server) to know about an elapsed period of time without activity on your server.  This is because of the nature of the HTTP client/Server protocol.  Servers cannot initiate communications.  Servers can behave like clients and initiate communications that way, but it's unlikely that you can get Google to set up this kind of app for you.

OTOH, it's easy to do for yourself.  Consider these two scripts.  The first takes a checkpoint.  You would add this functionality to the script you want to monitor.  It simply records the Unix timestamp of the time it ran in the checkpoint file.
http://iconoun.com/demo/temp_roger_checkpoint.php
<?php // demo/temp_roger_checkpoint.php

/**
 * http://www.experts-exchange.com/questions/28701201/How-to-monitor-specific-webpage-through-Google-analytics-API.html
 *
 * Make a timestamped checkpoint record
 */
error_reporting(E_ALL);
$url = 'temp_roger_checkpoint.txt';

file_put_contents($url, time());

Open in new window

The second script examines the checkpoint file and computes the elapsed time since the last checkpoint.  If it's more than 15 minutes, it can raise an alert, send an IM or email, connect to Twitter and tweet, etc.  You or your server administrator can set this up to run every minute.  There will be no measurable overhead load on the server.  You'll be able to get a notice as soon as the 15 minutes of inactivity has occurred.
http://iconoun.com/demo/temp_roger_cronjob.php
<?php // demo/temp_roger_cronjob.php

/**
 * http://www.experts-exchange.com/questions/28701201/How-to-monitor-specific-webpage-through-Google-analytics-API.html
 *
 * Examine a timestamped checkpoint record
 */
error_reporting(E_ALL);
$url = 'temp_roger_checkpoint.txt';

if (!$then  = file_get_contents($url))
{
    trigger_error("Missing file $url", E_USER_ERROR);
}
$now   = time();
$lapse = $now - $then;
$numft = number_format($lapse);
echo PHP_EOL . "IT HAS BEEN $numft SECONDS SINCE THE LAST CHECKPOINT";

if ($lapse > 15*60)
{
    echo PHP_EOL . "BETTER SEND THE AUTOMATED EMAIL!";
}

Open in new window

Avatar of roger v

ASKER

@Ray,

I think I haven't been able to clarify my requirement. I'm not sure why there would a script one and script two. Here's my requirement:

1. My website has a web page called mypage.html.
2. My website is configured in GA.
3. GA tracks the number of page hits for all the web pages in my website including mypage.html.
4. I need to check, once every 15 mins, if GA shows any hits for mypage.html.
5. If GA does show atleast one hit for mypage.html, I do nothing.
6. If GA does NOT show atleast one hit for mypage.html, I send out an email to recipients.
7. How do I build a php script, which integrates with GA's api, checks the number of hits for mypage.html as recorded by GA, and then either sends out an email or does not?

thanks,
roger
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of roger v

ASKER

Thanks Ray!