Home / Parsing Google Analytics data with PHP: A Series

Parsing Google Analytics data with PHP: A Series

At the start of 2009 I added a "Recent Posts" section to the sidebar navigation of this blog and decided I’d update it using data from Google Analytics. Unfortunately Analytics doesn’t have an API to get data but does have a function for sending data by email on regular basis either as a TSV, CSV, XML or PDF attachment.

Update May 2009: There is now a Google Analytics API and it’s much easier to use than the methods presented here. The posts in this series are still useful however as many of them show how to connect to mail servers, extract attachments from emails etc.

Read my Google Analytics API and PHP series for more details about the API and to download the PHP class I have created for accessing it.

End of update

 

Therefore a somewhat spordaic series of posts began appearing on this blog showing how to get Google Analytics data by email and use PHP’s IMAP functions to read through a mailbox and extract data from the attachments.

A full list of articles from this series is presented below. Included were a number of supplementary posts about how to do various additional things with PHP IMAP.

The series

To kick things off I looked at how to get Google Analytics to email reports manually (i.e. one-off) and automatically (i.e. on a daily etc basis without user intervention):

I’ve been using the PHP IMAP functions during this series so needed to look at how to connect to an IMAP server, download emails and extract the attachments. These were covered in the following posts:

Finally the series looked at how to then parse the attachments into a data array which could then be used to populate a database etc:

I’ll personally be downloading email from a Gmail account, so posted about what you need to do to be able to download mail from Gmail with IMAP and then downloading messages with PHP:

And in case of the "Fatal error: Call to undefined function imap_open()" error I posted how to install the PHP IMAP extension on CentOS/RHEL/Fedora and Debian: