connecting google analytics data api to dojo charts - php backend - php

I'm looking at feeding dojo charts with data from google analytics, within a Zend Framework app. Has anyone done this or have any overview as to how I would go about it? I see there is a dojox.data.GoogleSearchStore. Does it make sense to have a dojox.data.GoogleAnalyticsStore and is anyone working on something like this?

I did a project recently doing this exactly - presenting data from the Google Analytics API using Dojo Charts. I'm not sure if the approach I used was the best, but I can at least give you some pointers.
Daniel Hartmann has a proposal for a Zend_Gdata_Analytics component. It hasn't been approved yet however you can find his code on Github and it works perfectly. I used this to get all the data I needed from analytics.
The Google Analytics API itself is quite powerful but it takes a while to get your head round it. Try and understand the difference between dimensions and metrics from Google's docs. It helps if you think of the service as building queries that return a table of data (like SQL), rather than just one value. In this table, each metric you add to the query adds a column of data to the result, and dimensions are used to restrict and group the data overall. So for example:
$ga->newDataQuery()
->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_DATE)
->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS)
->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_VISITORS)
->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS);
gives you the total visits, visitors and page views for each day.
Analytics sometimes takes a few seconds to respond to queries (especially complex ones) so you'll want to cache the data. In my case I was selecting it at regular intervals by cron and storing it in a database.
On the Dojo side, I don't think dojox.data.GoogleSearchStore will help you. I used a combination of dojo.data.ItemFileWriteStore, dojox.charting.DataSeries and Zend_Dojo_Data, but I don't think my requirements would be typical. I'd suggest starting with the basics - get your graphs working with sample (hardcoded) data before your try and drop in your analytics. There are some tutorials on sitepen.com which I found useful.
Good luck!

Related

Setting an analytics custom metric server side

I'm using the GTM data layer to populate data through the enhanced ecommerce interface of Analytics. The goal is to provide detailed cost data so I can build a dashboard that shows profitability for my business. It's working great on a transaction basis and I am uploading shipping costs, product costs, discounts, and a host of other transaction data. However, my business also has fixed overhead costs. I want to upload that to analytics once per day so I can see the true profitability on a day by day basis. This requires it to be a server-side request from my PHP server. I am unfamiliar with how to set a custom metric from the server side. Does anyone know how I can send this once-per-day data to analytics from the server side? Would I send it as a pageview event? The variable name would be "fixed overhead". I'm not really sure where to start. Thanks in advance!
Sending data server-side to Google Analytics is entirely possible (and admittedly it is pretty daunting if you've not done it before).
The two best resources to use are the Google Analytics Measurement Protocol documentation and the Google Analytics Hit Builder. Use the parameter guide to prep the custom metric data specifically.
Here is my actual snippet that I use for all of my PHP projects (first ~150 lines or so). I'm certain there are better ways to do it, but at the very least it might help you figure out some of the complexities.
It's a lot of info to soak in, but I hope that gets you headed in the right direction!

Setting up an online server database and code my android native app to interact with it

Im developing a very simple native Android App containing a simple Main Menu with the Today, Yesterday, This Week, This Month and Search by Date options.
(I bought the lynda course: "Building Android and iOS Apps with Dreamweaver" with HTML5 and with the design and functionality of the app im not having too much trouble.)
What i entend with this app is this: i will write famous people profiles every day (between 1 and 5). So when people click (for example) in the Today option they will access to the profiles list that i have created for today (Yesterday and others is a check on the past written profiles from database).
So imagine that some android user clicked on today and will be presented with 3 profiles options ("Brad Pitt", "Shakira" and "Cristiano Ronaldo"), that i need the app to access my server database to update it (the "Today" profiles).
and finally...
Before the questions i want to say that i have searched on stackoverflow and found very similar answers, but im a novice on programming and when i'm reading the answers they can differ so much that i got confused going link on link documentation.
The Questions:
I want to create somekind of method that i could have a template with different profiles (Singer, Politician, Soccer Player) and click on somekind of button to start a new profile/article with Born Date, Occupation, Nationality, Biography and etc. Its this possible? How can i do it and in wich programming language?
What kind of server and what kind of database do i have to create and how to configure it to send the info to my app?
There is any server specifications that i must have for this to work the smoother and easiest possible? For this issue price is not a problem.
What kind of code should i write on my app so that it could get the "3 profiles update for today" from my website?
Its possible to show me some code example that would work with this simple step in my app of selectiong "Today" button on main menu and the app check for new profiles for today and present the user as an option? Because if i had this bit of code i could understand better how to do the rest with the profile details on the "Brad Pitt" option for example.
Hope you understood my questions. Thanks in advance. Have a nice day
Assuming that you're using the Phonegap Framework to develop your application, I would do it like so:
First of all get a Server/Webspace capable of running PHP Scripts and a MySQL Database.
You also have to rethink the way these applications work, for example you can't
configure it to send the info to my app
You need a Server Side Script (i would choose PHP for this, it's easy to learn and available on almost every Server). This PHP Script then queries your MySQL Database where all the information about the people is stored. On thing to remember is that your Clients will poll the server and request the content, you're not actively sending anything to Clients unless requested, that's just the way how HTTP works. The interface your Script is providing there is called a REST Interface.
Have a look at the link, it explains everything pretty good. Your output format should be JSON this makes it really nice to work with in the Client App later on. To do things like "what was posted today?" Have a look at how SQL Queries work and implement it in your Script.
Now for the client you can access this data by using JavaScript, most likely jQuery to simplify everything a bit. Use the jQuery $.getJSON function to access the data provided by your REST Interface. Now you can use basic jQuery to wrap this data up with HTML to present it to the user. I know that this is not "example code" or anything you requested, but it should point you into the right direction on how to achieve something like you want to do. Just do a google search for all the keywords listed above and keep reading about it, then you should be able to build a app like that.

Google Adwords API

I just have a quick question to see if this is possible with the Google Adwords API or if there is a better solution / service out there that I could use.
What we need to do is generate a Google Adwords report each month with some statistics. We need the report to automatically pull the following things:
# of clicks
Cost
Average Ad Position
Top 5 Keywords Clicked
Then, it should also compare how it did from the previous month and then provide a graph of the past 6 months activity.
Is this all possible? I am waiting for the adwords login from my company so I can go in and request the key and play around with it but in the mean time I just wanted to ask and see what you guys think. Is something like this difficult or pretty straight forward? Is there maybe a service already out there that does something like this? This will be for over 100 accounts.
What do you guys recommend?
All of this is possible using the API but the API may be overkill. The automated reporting features in Adwords are very customisable and you can have them generated at regular intervals and emailed to you with the data you mention.
You can find info on setting them up here: http://adwords.google.com/support/aw/bin/answer.py?hl=en&answer=12299
I used to have a number of python scripts that would generate all sorts of pretty graphs from the early Adwords API. It wasn't until a few years later I realised the automated reports could do it all and much more.
Try AdWords Scripts. With those, you could write a 30-line piece of Javascript, have it dump the output and graphs into a Google spreadsheet, and automatically execute once a month while emailing you about it. They have a few tutorials on the website that do very similar things.

Real time activity feed - code / platform implementation?

I am defining out specs for a live activity feed on my website. I have the backend of the data model done but the open area is the actual code development where my development team is lost on the best way to make the feeds work. Is this purely done by writing custom code or do we need to use existing frameworks to make the feeds work in real time? Some suggestions thrown to me were to use reverse AJAX for this. Some one mentioned having the client poll the server every x seconds but i dont like this because it is unwanted server traffic if there are no updates. I was also mentioned a push engine like light streamer to push from server to browser.
So in the end: What is the way to go? Is it code related, purely pushing SQL quires, using frameworks, using platforms, etc.
My platform is written in PHP codeignitor and DB is MySQL.
The activity stream will have lots of activities. There are 42 components on the social networking I am developing, each component has approx 30ish unique activities that can be streamed.
Check out http://www.stream-hub.com/
I have been using superfeedr.com with Rails and I can tell you it works really well. Here are a few facts about it:
Pros
Julien, the lead developer is very helpful when you encounter a problem.
Immediate push of new feed entries which support PubSubHubHub.
JSon response which is perfect for parsing whoever you'd like.
Retrieve API in case the update callback fails and you need to retrieve the latest entries for a given feed.
Cons
Documentation is not up to the standards I would like, so you'll likely end up searching the web to find obscure implementation details.
You can't control how often superfeedr fetches each feed, they user a secret algorithm to determine that.
The web interface allows you to manage your feeds but becomes difficult to use when you subscribe to a loot of them
Subscription verification mechanism works synchronous so you need to make sure the object URL is ready for the superfeedr callback to hit it (they do provide an async option which does not seem to work well).
Overall I would recommend superfeedr as a good solution for what you need.

Libraries and pseudocode for physical Dashboard/Status board

OK, so I bought a 46" screen for the office yesterday, and with the imminent risk of being accused for setting up an "elaborate World Cup procrastination scheme", I'd better show my colleagues what it's meant for ;)
Looking at my simple sketch, and at these great projects from which I was inspired, I would like to get some input on the following:
Pseudocode for the skeleton: As some methods should be called every 24 hours ("Today's date in the heading"), others at 60 second intervals ("Twitter results"), what would be a good approach using JavaScript (jQuery) and PHP?
EDIT: Alsciende: I can agree that #1 and #8 are too vague. Therefore I remove #8 and try to clarify #1: With "Pseudocode for the skeleton", I basically mean could this be done entirely using JavaScript timers and how would you set up the various timers?
Library for Google Analytics: Which libraries support the Google Analytics API and can produce neat charts. Preferably HTML5, JavaScript-based like Protovis.
Library for Twitter: Which libraries would you recommend for fetching twitter search results and latest tweets from profiles.
Libraries for Typography/CSS/HTML5: Trying to learn some HTML5 etc. in the process, please advice on any other typography/css libraries that could be of relevance.
Scraping/Parsing? I'll give you a concrete example: Trying to fetch today's menu from this restaurant's website, how would you go about? (it's in Swedish - but you get the point - sorry ;) )
Real-time stats? I'm using the WassUp-plugin for WordPress to track real-time visitors on our website. Other logging software (AWStats etc.) is probably also installed on the webserver. Any ideas on how to extract information from these and present in real-time on the dashboard?
Browser choice? Which Browser and OS would you pick? Stable, Full-screen, HTML5.
alt text http://www.freeimagehosting.net/uploads/cb7af2ef28.png
I've built a dashboard similar to what you're talking about for our office. I spent about a day working on it, the possibilities are really (pretty much) endless. Basically, all the computational stuff I handle via PHP and do interval AJAX calls to the appropriate PHP script, which returns JSON data to present.
#2:
For graphs, I use/recommend flot (http://code.google.com/p/flot/). The documentation isn't really that great, but once you figure out how things generally work - it's a great library, and it generates graphs using HTML5 Canvas tag.
I've not integrated external libraries with Google Analytics before, but I assume you could pull data from analytics and format it for flot to build appropriate graphs for. This might be the hard-way around, but I'm more familiar with flot than most other graphing libraries (and it doesn't suck, as much as a lot of others do) so for me, this would be the easiest way to get it done.
#3:
For twitter, it's pretty easy to pull data from their search API using JSON-P. Basically what this does, is dynamically adds a <script> tag to your DOM, which GET parameters that twitter interprets, then calls a predefined javascript method (which you pass via the URI) with a json-encoded hash of the results.
#5:
Scraping and parsing individual sites is going to be a painstaking process. Every site is going to have it's own "pattern" (or non-pattern) for publishing their daily menu or specials. I'd build a "menu" script which knew how to call a few functions, and write a function / class for scraping each restaurant's site which you're interested in showing the menu for in PHP (or whatever other language you're comfortable with). It can reply with json, which is (imo) the easiest way to manipulate/process data in Javascript.
#6:
Real time stats are pretty much the same as #5. I'd build a couple classes that knew how to fetch the statistics from whatever data sources I was interested in pulling from, and present the data in json to javascript, via an ajax call.
#1: Writing javascript code to load data on a timer is really simple, look into the setInterval, clearInterval, setTimeout, and clearTimeout methods. They all take a function name (or closure) and a timeout to wait before calling that function (in ms). You could easily call a master timer function every 60 seconds which would basically be a "scheduler" or a "cron" style function, which would just look for the stuff that needed to run "right now" and execute those functions from the scheduler.
Hopefully this gives you some ideas on where to go, and how to go about getting there.
For the Rails Rumble we developed Boarrd that is exactly what you would like to develop!
We were impressed by Panic too :)
In our team page on RailsRumble you'll find details about the tools used. I know that is not in PHP but maybe you'll try our tool and decide for better development environment ;)

Categories