Web Developer

Connect to Google Analytics Data in Air/ActionScript

Google Analytics blog published a post to present a new library to access Google Analytics Data Api. You can get this open source library from here.

In the following example you can see one of the ways to get data without using GAView.

	import com.denivip.ga.APILoader;
	import com.denivip.ga.GAAccount;
	import com.denivip.ga.dimensions.*;
	import com.denivip.ga.feed.*;
	import com.denivip.ga.filter.Filter;
	import com.denivip.ga.filter.FilterItem;
	import com.denivip.ga.filter.FilterOperator;
	import com.denivip.ga.metrics.*;

_api = new APILoader();
_api.setPeriod(_dateStart, _dateEnd);
_api.setDimensions(new Array(new VisitorDateDimension()));
_api.setMetrics(new Array(new VisitorVisitsMetric()));

var sgm:Filter = new Filter(new FilterItem("gaid::-7")); // Direct Traffic

protected function response(data:Array):void
	var total:int;
	var i:int; 
	var j:int;
	var response:DataFeedResponse;
	var entries:Array;
	var ent:DataFeedEntry;
	var metrics:Array;
	var dimensions:Array;
	var met:Metric;
	var dim:Dimension;
	if(data!=null) if(data.length>0) response = data[0];
	if(response!=null) {
		entries = response.entries;
		total = entries.length;
		for(i = 0; i<total; i++){
			ent = entries[i];
			metrics = ent.metrics;
			dimensions = ent.dimensions;
			for(j = 0; j<metrics.length; j++){
				met = metrics[j];
				trace("metric "+met.name+" = "+met.value);
			for(j = 0; j<dimensions.length; j++){
				dim = dimensions[j];
				trace("dimension "+dim.name+" = "+dim.value);

1 Comentario

  1. Hi, the link to the swc is no longer active. Could you send me a zip with the files? or upload it anywhere if you can, please.


Deja un comentario

Tu dirección de correo electrónico no será publicada.




Tema por Anders NorenArriba ↑