[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

07/16/2009, Eric Rudnick
"We're sorry..."
I've been using this tag to integrate Google Analytics data into our web-based CRM, but I'm having an issue. Occasionally, the response from Google will be, instead of XML, a page saying: An error occurred while processing your request. Error Information Error Message: libxml2 error: AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: b line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: td line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: tr line 13 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: table line 12 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: body line 11 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: html line 1 and font Extra content at the end of the document at: onCreate with params: @\n\n\n403 Forbidden\n\n\n\n\n\n\n\n\n
Google\n\n\n\n\n\n
 Error 
\n
\n
\n

We're sorry...

\n

... but your query looks similar... at: /test_code/eric_test.lasso on line: 89 at position: 19 Error Code: -9956 Action: nothing Database: -- Table/Layout: -- Response: /test_code/eric_test.lasso Lasso Site: default (1) Client Address: 192.168.167.172 Client IP: 192.168.167.172 Client Type: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19 Server Date: Thursday, July 16, 2009 Server Time: 10:55:46 AM Apparently, Google thinks the request is an automated request from a virus or spyware application. When this happens, I'm pretty much shut out of google analytics for a period of time ranging from a few minutes to over an hour. Does anyone know what is going wrong here?

07/16/2009, Eric Rudnick
"We're sorry..."
I've been using this tag to integrate Google Analytics data into our web-based CRM, but I'm having an issue. Occasionally, the response from Google will be, instead of XML, a page saying: An error occurred while processing your request. Error Information Error Message: libxml2 error: AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: b line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: td line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: tr line 13 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: table line 12 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: body line 11 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: html line 1 and font Extra content at the end of the document at: onCreate with params: @\n\n\n403 Forbidden\n\n\n\n\n\n\n\n\n
Google\n\n\n\n\n\n
 Error 
\n
\n
\n

We're sorry...

\n

... but your query looks similar... at: /test_code/eric_test.lasso on line: 89 at position: 19 Error Code: -9956 Action: nothing Database: -- Table/Layout: -- Response: /test_code/eric_test.lasso Lasso Site: default (1) Client Address: 192.168.167.172 Client IP: 192.168.167.172 Client Type: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19 Server Date: Thursday, July 16, 2009 Server Time: 10:55:46 AM Apparently, Google thinks the request is an automated request from a virus or spyware application. When this happens, I'm pretty much shut out of google analytics for a period of time ranging from a few minutes to over an hour. Does anyone know what is going wrong here?

07/16/2009, Eric Rudnick
"We're sorry..."
I've been using this tag to integrate Google Analytics data into our web-based CRM, but I'm having an issue. Occasionally, the response from Google will be, instead of XML, a page saying: An error occurred while processing your request. Error Information Error Message: libxml2 error: AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: b line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: td line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: tr line 13 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: table line 12 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: body line 11 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: html line 1 and font Extra content at the end of the document at: onCreate with params: @\n\n\n403 Forbidden\n\n\n\n\n\n\n\n\n
Google\n\n\n\n\n\n
 Error 
\n
\n
\n

We're sorry...

\n

... but your query looks similar... at: /test_code/eric_test.lasso on line: 89 at position: 19 Error Code: -9956 Action: nothing Database: -- Table/Layout: -- Response: /test_code/eric_test.lasso Lasso Site: default (1) Client Address: 192.168.167.172 Client IP: 192.168.167.172 Client Type: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19 Server Date: Thursday, July 16, 2009 Server Time: 10:55:46 AM Apparently, Google thinks the request is an automated request from a virus or spyware application. When this happens, I'm pretty much shut out of google analytics for a period of time ranging from a few minutes to over an hour. Does anyone know what is going wrong here?

07/16/2009, Eric Rudnick
"We're sorry..."
I've been using this tag to integrate Google Analytics data into our web-based CRM, but I'm having an issue. Occasionally, the response from Google will be, instead of XML, a page saying: An error occurred while processing your request. Error Information Error Message: libxml2 error: AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: b line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: td line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: tr line 13 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: table line 12 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: body line 11 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: html line 1 and font Extra content at the end of the document at: onCreate with params: @\n\n\n403 Forbidden\n\n\n\n\n\n\n\n\n
Google\n\n\n\n\n\n
 Error 
\n
\n
\n

We're sorry...

\n

... but your query looks similar... at: /test_code/eric_test.lasso on line: 89 at position: 19 Error Code: -9956 Action: nothing Database: -- Table/Layout: -- Response: /test_code/eric_test.lasso Lasso Site: default (1) Client Address: 192.168.167.172 Client IP: 192.168.167.172 Client Type: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19 Server Date: Thursday, July 16, 2009 Server Time: 10:55:46 AM Apparently, Google thinks the request is an automated request from a virus or spyware application. When this happens, I'm pretty much shut out of google analytics for a period of time ranging from a few minutes to over an hour. Does anyone know what is going wrong here?

07/16/2009, Eric Rudnick
"We're sorry..."
I've been using this tag to integrate Google Analytics data into our web-based CRM, but I'm having an issue. Occasionally, the response from Google will be, instead of XML, a page saying: An error occurred while processing your request. Error Information Error Message: libxml2 error: AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: b line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: td line 14 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: tr line 13 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: table line 12 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: body line 11 and font AttValue: " or ' expected attributes construct error Couldn't find end of Start Tag font line 14 Opening and ending tag mismatch: html line 1 and font Extra content at the end of the document at: onCreate with params: @\n\n\n403 Forbidden\n\n\n\n\n\n\n\n\n
Google\n\n\n\n\n\n
 Error 
\n
\n
\n

We're sorry...

\n

... but your query looks similar... at: /test_code/eric_test.lasso on line: 89 at position: 19 Error Code: -9956 Action: nothing Database: -- Table/Layout: -- Response: /test_code/eric_test.lasso Lasso Site: default (1) Client Address: 192.168.167.172 Client IP: 192.168.167.172 Client Type: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19 Server Date: Thursday, July 16, 2009 Server Time: 10:55:46 AM Apparently, Google thinks the request is an automated request from a virus or spyware application. When this happens, I'm pretty much shut out of google analytics for a period of time ranging from a few minutes to over an hour. Does anyone know what is going wrong here?

09/28/2008, Brian K. Middendorf
Re: multiple sites
Look at the "id" parameter passed in the URL for each site when accessing Analytics through a browser. Pass the appropriate "id" value (it will be a number) for each site as the "Account" parameter of the Google_Analytics tag.
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

Support tagSwap.net