Data Capture Automation (CRON) - PromInc/organic-search-analytics GitHub Wiki

CRON Functionality

What is CRON

CRON (or crontab) is a job scheduler method for running scheduled tasks on Linux/Unix based systems. Because Mac OS X is based on Linux/Unix it is available to run on those systems as well, however depending on the version of the OS it may not be enabled by default. Windows does not use CRON as it has Windows scheduler.

Version Available

This functionality was added in version 2.5.2

Parameters

A list of what parameters can be passed in can be found at this article: Data Capture Parameters

Example Scripts

Linux

0 1 * * * /path/to/osa/installation/data-capture-run.php googleSearchAnalytics http://yourdomain.com/ `date --date='4 days ago' '+\%Y-\%m-\%d'`

Linux (multiple domains)

0 1 * * * for DOMAIN in http://yourdomain.com/ https://www.example.com; do /path/to/osa/installation/data-capture-run.php googleSearchAnalytics $DOMAIN `date --date='4 days ago' '+\%Y-\%m-\%d'`; done;

OSX

0 1 * * * /path/to/osa/installation/data-capture-run.php googleSearchAnalytics 'http://yourdomain.com/' `date -v -4d '+%Y-%m-%d'`

CRON Resources

CRON on Windows via XAMPP

CRON is not available under Windows or XAMPP. Some solutions for using the same functionality however can be found here: http://stackoverflow.com/questions/17442040/setting-up-a-cronjob-in-windows-xampp

Notes

  • The most recent date available from Google is 4 days ago. Adjust the date in your CRON request accordingly.

PHP Automation Script

At times you may want to automate this via PHP. This may be handy if you have a server with CPanel - that often times is limited to just running PHP scripts. This code example could be used in that scenario.

<?php
$DOMAINS = array( "https://www.domain1.com/", "https://www.domain3.com/", "https://www.domain3.com/" );
foreach( $DOMAINS as $DOMAIN ) {
    file_get_contents( 'https://www.domainhostingosa.com/organic-search-analytics/data-capture-run.php?type=googleSearchAnalytics&domain=' . $DOMAIN . '&date=' . date( 'Y-m-d', strtotime('-5 day') ) );
}
?>

OS X Automation via AppleScript

On your Mac OS X computer you could utilize AppleScript to automate the capturing of data. Create an AppleScript (saved to your computer) based on this code example updating the domains where needed.

on updateOsaData()
	try
		do shell script "for DOMAIN in https://www.domain1.com/ https://www.domain3.com/ https://www.domain3.com/; do curl -G https://www.domainhostingosa.com/organic-search-analytics/data-capture-run.php --data type=googleSearchAnalytics --data date=`date -v -4d '+%Y-%m-%d'` --data-urlencode domain=$DOMAIN; done;"
	on error
		## handle error
	end try
end updateOsaData

updateOsaData()

Then schedule this script to run daily using the Calendar app. Create an event. Choose Alert -> Custom -> Open File and select your AppleScript from above. Set this to be a repeating event.