[google_analytics]

Description

Link: [google_analytics]
Author: Jason Huck
Category: Utility
Version: 8.5.x
License: Public Domain
Posted: Aug. 02, 2007
Updated: Aug. 07, 2007
More by this author...
This custom type retrieves reports from Google Analytics. A wide variety of reports can be retrieved in a number of formats, including XML, PDF, and CSV.

->getreport - Retrieves the requested report.
    -name - string, required, the report to retrieve. At the time of this writing, the available report names were:
    DashboardReport
    VisitorsOverviewReport
    GeoMapReport
    VisitorTypesReport
    LanguagesReport
    VisitsReport
    UniqueVisitorsReport
    PageviewsReport
    AveragePageviewsReport
    TimeOnSiteReport
    BounceRateReport
    LoyaltyReport
    RecencyReport
    LengthOfVisitReport
    DepthOfVisitReport
    BrowsersReport
    PlatformsReport
    OsBrowsersReport
    ColorsReport
    ResolutionsReport
    FlashReport
    JavaReport
    NetworksReport
    HostnamesReport
    SpeedsReport
    TrafficSourcesReport
    DirectSourcesReport
    ReferringSourcesReport
    SearchEnginesReport
    AllSourcesReport
    KeywordsReport
    AdwordsReport
    KeywordPositionReport
    CampaignsReport
    AdVersionsReport
    ContentReport
    TopContentReport
    ContentByTitleReport
    ContentDrilldownReport
    EntrancesReport
    ExitsReport

    -from - date, required, the start date for period of time to report against.

    -to - date, required, the end date for the period of time to report against.

    -format - integer from 0 to 3, optional. Defaults to 1. Values are:
        0 - PDF
        1 - XML
        2 - CSV
        3 - TSV

    -rows - integer, optional. Number of rows to return. Defaults to 10.

Parameters

none


Sample Usage

// Retrieve and display the XML version of 
// the Keywords Report for the last month.

// Set the content type to XML
content_type('text/xml');

// Initialize the custom type and log in
// to your Google account.
var('ga') = google_analytics(
	-email='xxxxxxxxx',
	-password='xxxxxxxxx',
	-account=xxxxxxxxx
);

// Retrieve the desired report.
$ga->getreport(
	'KeywordsReport',
	-from=date->subtract( -month=1)&,
	-to=date
);
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
define_type(
	'google_analytics',
	-description='Retrieves reports from Google Analytics.'
);
	local(
		'account'	=	string,
		'cookies'	=	string			
	);
	
	define_tag(
		'oncreate',
		-req='email',
		-req='password',
		-req='account'
	);
		self->account = #account;
	
		local('pp') = array(
			'continue'	=	'http://www.google.com/analytics/home/?et=reset&hl=en-US',
			'service'	=	'analytics',
			'nui'		=	'1',
			'hl'		=	'en-US',
			'GA3T'		=	'X67XP8PK9ek',
			'Email'		=	#email,
			'Passwd'	=	#password, 
			'PersistentCookie'	=	'yes',
			'rmShown'	=	'1',
			'null'		=	'Sign in'
		);
		
		protect;
			local('login') = include_url(
				'https://www.google.com/accounts/ServiceLoginBoxAuth',
				-postparams=#pp,
				-retrievemimeheaders='hdr',
				-timeout=15
			);
		/protect;
	
		local('cookies') = string;
		
		iterate($hdr->find('Set-Cookie'), local('i'));
			#cookies += #i->value + ';';
		/iterate;
	
		#cookies->removetrailing(';');
		self->cookies = #cookies;
	/define_tag;

	define_tag(
		'getreport',
		-req='name',
		-req='from',	-type='date',
		-req='to',		-type='date',
		-opt='format',	-type='integer',
		-opt='rows',	-type='integer',
		-encodenone
	);
		local('gp') = array(
			'fmt'	=	(local_defined('format') ? #format | 1),
			'id'	=	self->account,
			'pdr'	=	(#from->format('%Y%m%d') + '-' + #to->format('%Y%m%d')),
			'cmp'	=	'average',
			'trows'	=	(local_defined('rows') ? #rows | 10),
			'rpt'	=	#name
		);
	
		protect;
			local('data') = include_url(
				'https://www.google.com/analytics/reporting/export',
				-getparams=#gp,
				-sendmimeheaders=array('Cookie'=self->cookies),
				-timeout=15
			);
		/protect;
		
		return(#data);
	/define_tag;
/define_type;

 

Related Tags



Comments

08/04/2007, Dominique Guardiola
multiple sites
it works great, thanks for this code! is there a way to get others reports than the first one listed ? I access all my reports from the same google account. I guess I can create multiples accounts, one for each site :) Great thanks again, I dreamed of this tag!
Email:


Password:



Newest

Most Popular