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
LVL 1
roger vAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
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.
roger vAuthor Commented:
@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,
Ray PaseurCommented:
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.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

roger vAuthor Commented:
@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
Ray PaseurCommented:
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

roger vAuthor Commented:
@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
Ray PaseurCommented:
I know how to solve this notification problem because I've done it before, and the scripts I posted here will do that for you.  I do not know how to force this process to use the Google Analytics API -- that would seem to be a requirement to use the wrong tool.  And in any case, this would be a research and development project for me, and as a professional programmer I would need to be paid for the time and knowledge.  E-E is pretty good at sharing questions and answers, but E-E does not provide any compensation for us to develop applications with specific API requirements.  

I'll sign off now.  Best of luck with your project, ~Ray

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
roger vAuthor Commented:
Thanks Ray!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Google Apps

From novice to tech pro — start learning today.