This post looks at how to send any report from within Google Analytics by email either as a one-off email or on a scheduled basis (daily, weekly, monthly or quarterly). While this may appear to be off topic for this blog, I will be looking at how to extract data from the attachments sent in the emails using PHP in a later post.
Unfortunately Google Analytics does not provide an API to be able to get data directly from it for use in other applications. However, you can send the data by scheduled email and then have a separate process extract the data from the email and then do whatever you need with it. While this is not ideal it does at least mean you can automate the use of data from Analytics with a little work.
Sending data from any report
To send data from Google Analytics by email, view the report first. The screenshot below is looking at the report showing top content. The red arrow points to the “Email” button which appears at the top of every report in Analytics.
Sending an email now
Click the “Email” button which I have highlighted with the red arrow in the screenshot above, and you will go through to the setting up email page as shown in the screenshot below. You have the options to “Send Now” which is selected by default, “Schedule” or “Add to Existing”. You can send the email to yourself now to see what the formatting etc is like.
Simply fill out any of the optional form fields, select which format you want (you can get it as a PDF with graphs and data, an XML file, CSV (comma separated) file or TSV (tab separated) file), the annoying captcha field and then click the “Send” button.
I don’t know why, but to me Google’s captcha images are always really hard to read.
Scheduling an email daily/weekly/monthly/quarterly
If you want to schedule the email, click the “Schedule” tab and you’ll see a slightly different variation of the form as shown in the screenshot below.
Once you click the “Schedule” button you are returned to the report you were on and there’s a message to say it’s been scheduled.
Deleting a scheduled email
If you need to delete a scheduled email to no longer receive it, click the “Emails” option in the left side navigation. This is shown in the screenshot below and highlighted with the red arrow.
This will now show a list of scheduled emails as shown in the example screenshot below.
Simply click the trash can icon next to the email you want to delete. You will be prompted to confirm you really do want to delete the report and then it will be deleted once confirmed.
Extracting data from the attachment with PHP
In the next two to three weeks I will have a series of posts about how to extract the data from the emails with PHP. The first will look at how to get attachments out of emails with PHP and the next two will look at how to get the CSV/TSV versions of the data and the XML version of the data. Make sure to subscribe to my RSS feed (details below) to ensure you don’t miss out.