Permalink
Browse files

Modified for missing getProfiles() method

getProfiles() method does not exist. Worked out how to get profiles
while implementing this code in a project and updated the index.cfm and
README accordingly.
  • Loading branch information...
ddspringle committed May 29, 2014
1 parent 99ee84c commit 36d5f86554ec92d133ecf6547b3fb834e59c40ca
Showing with 83 additions and 8 deletions.
  1. +11 −3 README.md
  2. +72 −5 index.cfm
@@ -102,11 +102,19 @@ Now you can call methods to access your analytics data.

# Core Reporting API #

Firstly, get the list of available profiles within your analytics account using the **getProfiles()** method:
Firstly, get the list of available accounts within your analytics account using the **listAccounts()** method:

<cfset stuProfiles = application.objGA.getProfiles() />
<cfset stuAccounts = application.objGA.listAccounts() />

This returns a struct of arrays, each item in the array being a profile (site or app) set up within Google Analytics.
This returns a struct of arrays, each item in the array being an account set up within Google Analytics. You will need the account **id** to get a list of web properties under that account using the **listWebProperties()** method:

<cfset stuWebProperties = application.objGA.listWebProperties(accountId = [id]) />

This returns a struct of arrays, each item in the array being a web property set up within the specified Google Analytics account. You will need the account **id** and the web property **id** to get a list of profiles using the **listProfiles()** method:

<cfset stuProfiles = application.objGA.listProfiles(accountId = [id], webPropertyId = [id]) />

This returns a struct of arrays, each item in the array being a profile set up within the specified Google Analytics account and web property. You will need the profile **id** to make requests for analytics data through the Core Reporting API.

The main method available to use for all requests to the Core Reporting API is the generic **queryAnalytics()** method.
This method accepts all parameters from the remote API, and allows you to query on a specific profile:
@@ -10,7 +10,7 @@
We'll use this to detect if we are "logged in" to the API.
--->
<cfset structInsert(session, "google_api_auth", authResponse) />
<cflocation url="index.cfm" addtoken="false" />
<cflocation url="index.cfm?accounts" addtoken="false" />
<cfelse>
<!---
Failure to authenticate.
@@ -29,8 +29,77 @@

<a href="index.cfm?reinit=true">Reload</a>

<cfdump var="#application.objGA#">

<!---
check if we're ready to select an account
--->
<cfif structKeyExists(URL, 'accounts')>

<!---
we are, get the list of accounts
--->
<cfset stuData = application.objGA.listAccounts() />
<!---
present the accounts to the user to select from
--->
<h3>Select Account:</h3>
<cfloop from="1" to="#ArrayLen(stuData.items)#" index="iX">
<cfoutput><p><a href="#CGI.SCRIPT_NAME#?properties=&amp;accountId=#stuData.items[i].id#">#stuData.items[i].name#</a></p></cfoutput>
</cfloop>

<!---
otherwise, check if we're ready to select a web property
--->
<cfelseif structKeyExists(URL, 'properties')>

<!---
we are, get the list of web properties from the selected account
--->
<cfset stuData = application.objGA.listWebProperties(accountId = URL.accountId) />
<!---
present the properties to the user to select from
--->
<h3>Select Web Property:</h3>
<cfloop from="1" to="#ArrayLen(stuData.items)#" index="iX">
<cfoutput><p><a href="#CGI.SCRIPT_NAME#?profiles=&amp;accountId=#URL.accountId#&amp;propertyId=#stuData.items[i].id#">#stuData.items[i].name#</a></p></cfoutput>
</cfloop>

<!---
otherwise, check if we're ready to select a profile
--->
<cfelseif structKeyExists(URL, 'profiles')>

<!---
we are, get the list of profiles from the selected account and web property
--->
<cfset stuData = application.objGA.listProfiles(accountId = URL.accountId, webPropertyId = URL.propertyId) />
<!---
present the profiles to the user to select from
--->
<h3>Select Profile:</h3>
<cfloop from="1" to="#ArrayLen(stuData.items)#" index="iX">
<cfoutput><p><a href="#CGI.SCRIPT_NAME#?analytics=&amp;profileId=#stuData.items[i].id#">#stuData.items[i].name#</a></p></cfoutput>
</cfloop>

<!---
otherwise, check if we're ready to gather analytics
--->
<cfelseif structKeyExists(URL, 'analytics')>

<!---
we are, get the list of profiles from the selected account and web property
--->
<cfset stuData = application.objGA.queryAnalytics(profileId = URL.profileId) />
<!---
dump the analytics data
--->
<cfdump var="#stuData#" label="Analytics Data" />


</cfif>

<!---
<cfdump var="#application.objGA#">
--->
<!---
<cfset stuData = application.objGA.queryAnalytics(
profileID = "< your profile ID >",
@@ -53,8 +122,6 @@
) />
--->

<!---<cfset stuData = application.objGA.getProfiles() />--->

<!--- <cfdump var="#stuData#"> --->

<cfelse>

0 comments on commit 36d5f86

Please sign in to comment.