Exception in Birt while loading class in Google Analytics client library [message #639706] |
Wed, 17 November 2010 09:37  |
Eclipse User |
|
|
|
Hi all!
I'm trying to make a report in Birt 2.6.2 which will present data fetched from Google Analytics service. From forum messages and documentation, I've concluded that scription data source should be used for this purpose.
I developed a java class which logs in to GA and fetches data. This class has dependancies to GA client libraries. I've put this class and libs into scriptlib folder and I also included GA libs on Report Designer classpath.
Java class is instantiated in "open" method for a data set.
The problem occures when class instatiates one of the Google's classes from GA client lib when report is run in Report Designer.
This is the stacktrace of the exception:
org.eclipse.birt.report.service.api.ReportServiceException: Error happened while running the report.
at org.eclipse.birt.report.service.ReportEngineService.throwDummyException(ReportEngineService.java:1097)
at org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:926)
at org.eclipse.birt.report.service.BirtViewerReportService.runAndRenderReport(BirtViewerReportService.java:973)
at org.eclipse.birt.report.service.actionhandler.BirtGetPageAllActionHandler.__execute(BirtGetPageAllActionHandler.java:131)
at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)
at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPageAll(BirtDocumentProcessor.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)
at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)
at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:939)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: org.eclipse.birt.report.engine.api.EngineException: Error happened while running the report.
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:209)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)
at org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:920)
... 49 more
Caused by: java.lang.ExceptionInInitializerError
at bumblehood.reporting.GoogleAnalyticsDataFetcher.(GoogleAnalyticsDataFetcher.java:61)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.mozilla.javascript.MemberBox.newInstance(MemberBox.java:194)
at org.mozilla.javascript.NativeJavaClass.constructSpecific(NativeJavaClass.java:281)
at org.mozilla.javascript.NativeJavaClass.construct(NativeJavaClass.java:200)
at org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:2327)
at org.mozilla.javascript.gen.c10._c1(:3)
at org.mozilla.javascript.gen.c10.call()
at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
at org.mozilla.javascript.gen.c11._c0(:0)
at org.mozilla.javascript.gen.c11.call()
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
at org.mozilla.javascript.gen.c11.call()
at org.mozilla.javascript.gen.c11.exec()
at org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateRawScript(JavascriptEvalUtil.java:95)
at org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateScript(JavascriptEvalUtil.java:134)
at org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJSAsExpr(ScriptEvalUtil.java:1001)
at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:76)
at org.eclipse.birt.report.engine.script.internal.DtEScriptExecutor.handleJS(DtEScriptExecutor.java:90)
at org.eclipse.birt.report.engine.script.internal.DataSetScriptExecutor.handleJS(DataSetScriptExecutor.java:219)
at org.eclipse.birt.report.engine.script.internal.ScriptDataSetScriptExecutor.handleOpen(ScriptDataSetScriptExecutor.java:88)
at org.eclipse.birt.data.engine.impl.ScriptDataSetRuntime.open(ScriptDataSetRuntime.java:80)
at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor$CustomDataSet.open(PreparedScriptDSQuery.java:247)
at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor.executeOdiQuery(PreparedScriptDSQuery.java:223)
at org.eclipse.birt.data.engine.impl.QueryExecutor.execute(QueryExecutor.java:1094)
at org.eclipse.birt.data.engine.impl.ServiceForQueryResults.executeQuery(ServiceForQueryResults.java:232)
at org.eclipse.birt.data.engine.impl.QueryResults.getResultIterator(QueryResults.java:172)
at org.eclipse.birt.report.engine.data.dte.QueryResultSet.(QueryResultSet.java:98)
at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:168)
at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:265)
at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1876)
at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)
at org.eclipse.birt.report.engine.executor.TableItemExecutor.execute(TableItemExecutor.java:62)
at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)
at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)
at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)
at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:90)
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:99)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:180)
... 51 more
Caused by: java.lang.NullPointerException
at com.google.gdata.client.Service.(Service.java:97)
... 95 more
The java code for root NPE is:
public class Service {
private static final String SERVICE_VERSION =
"GData-Java/" + Service.class.getPackage().getImplementationVersion() // <------ THIS IS LINE WHICH THROWS NPE
+ "(gzip)"; // Necessary to get GZIP encoded responses
....
Does anyone understands why this line causes NPE?
Thanks,
Marko
[Updated on: Wed, 17 November 2010 09:57] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Exception in Birt while loading class in Google Analytics client library [message #667273 is a reply to message #667264] |
Wed, 27 April 2011 15:14   |
Eclipse User |
|
|
|
i found a fine example which gave me an idea. I was having an issue with connecting report script and java objects, but i made it.
Thank you for your reponse Jason.
the useful link that i found is on my other computer, i will paste it here if i don't forget (:
[quote title=Jason Weathersby wrote on Wed, 27 April 2011 19:49]I have an example built but I have not written up yet. I will try to do
this tomorrow. The only issue I have is that the example uses my
private google account settings. What issue are you having?
Jason
On 4/27/2011 5:15 AM, piratejackus wrote:
> Hello Jason,
>
> I'm trying to use Google Analytics as a data source in my report and i
> would like to follow an example. So, Is there any progress on this issue?
>
> Thanks.
>
> Jason Weathersby wrote on Wed, 22 December 2010 16:01 | Meghan,
>
> I went through building an example but I am still having issues with the
> classpath. Once I get that worked out I will post something.
>
> Jason
|
[Updated on: Wed, 27 April 2011 17:55] by Moderator
|
|
|
Re: Exception in Birt while loading class in Google Analytics client library [message #667281 is a reply to message #667273] |
Wed, 27 April 2011 16:16   |
Eclipse User |
|
|
|
I went back through my example and realized that I did not get this to
work. There is a class loader issue with one of the Google static
variables. Did you get your example to work?
Jason
On 4/27/2011 3:14 PM, piratejackus wrote:
> i found a fine example which gave me an idea. I was having an issue with
> connecting report script and java objects, but i made it.
> Thank you for your reponse Jason.
>
> the useful link that i found is on my other computer, i will paste it
> here i don't forget (:
>
> [quote title=Jason Weathersby wrote on Wed, 27 April 2011 19:49]I have
> an example built but I have not written up yet. I will try to do this
> tomorrow. The only issue I have is that the example uses my private
> google account settings. What issue are you having?
>
> Jason
>
> On 4/27/2011 5:15 AM, piratejackus wrote:
>> Hello Jason,
>>
>> I'm trying to use Google Analytics as a data source in my report and i
>> would like to follow an example. So, Is there any progress on this issue?
>>
>> Thanks.
>>
>> Jason Weathersby wrote on Wed, 22 December 2010 16:01
>> Meghan,
>> >
>> > I went through building an example but I am still having issues with
>> the
>> > classpath. Once I get that worked out I will post something.
>> >
>> > Jason
>
>
|
|
|
Re: Exception in Birt while loading class in Google Analytics client library [message #667296 is a reply to message #667281] |
Wed, 27 April 2011 17:53   |
Eclipse User |
|
|
|
Hi Jason,
I can make queries in google analytics and pass the data to my objects and then use them with the javascript (Report Scripting tool) in the reports. More simply; i can use google analytics with POJO s, as a scripted data source, in my reports.
If you like, i can give you a more detailed information on my basic project tomorrow (after about 9-10 hours). I didn't have any big problems with that.
Just let me know.
Jason Weathersby wrote on Wed, 27 April 2011 22:16 | I went back through my example and realized that I did not get this to
work. There is a class loader issue with one of the Google static
variables. Did you get your example to work?
Jason
On 4/27/2011 3:14 PM, piratejackus wrote:
> i found a fine example which gave me an idea. I was having an issue with
> connecting report script and java objects, but i made it.
> Thank you for your reponse Jason.
>
> the useful link that i found is on my other computer, i will paste it
> here i don't forget (:
>
> Jason Weathersby wrote on Wed, 27 April 2011 19:49 | I have
> an example built but I have not written up yet. I will try to do this
> tomorrow. The only issue I have is that the example uses my private
> google account settings. What issue are you having?
>
> Jason
>
> On 4/27/2011 5:15 AM, piratejackus wrote:
>> Hello Jason,
>>
>> I'm trying to use Google Analytics as a data source in my report and i
>> would like to follow an example. So, Is there any progress on this issue?
>>
>> Thanks.
>>
>> Jason Weathersby wrote on Wed, 22 December 2010 16:01
>> Meghan,
>> >
>> > I went through building an example but I am still having issues with
>> the
>> > classpath. Once I get that worked out I will post something.
>> >
>> > Jason
>
>
|
|
[Updated on: Thu, 28 April 2011 11:42] by Moderator
|
|
|
|
|
|
|
|
|
|
Re: Exception in Birt while loading class in Google Analytics client library [message #667596 is a reply to message #667570] |
Fri, 29 April 2011 16:12   |
Eclipse User |
|
|
|
We actually got this working.
We downloaded the following jars:
gdata-analytics-2.1
gdata-analytics-meta-2.1
gdata-client-1.0
gdata-client-meta-1.0
gdata-core-1.0
google-collect-1.0-rc1
The class files were unpacked and stored in the plugin folder of our Eclipse directory. My path looks like this:
C:\Eclipse\eclipse\plugins\org.eclipse.birt.report.viewer_2. 6.1.v20100913\birt\WEB-INF\classes\com\google\gdata
We've also created another directory under classes\com\[remainingpath] that stores the following class files:
AnalyticsServiceAdapter.class, PriorityFutureTask.class, ThrottledPriorityBlockingQueue.class, and UsageData.class
It is this set of class files that is referenced by our data set.
in the data set open event we have code like this:
count = 0;
var myUrl = 'https://www.google.com/analytics/feeds/data' +
// this is your google account ID
'?ids=ga%##### +
'&dimensions=ga%3Adate%2Cga%3ApagePath' +
'%2Cga%3Acountry' +
'%2Cga%3Aregion' +
'&metrics=ga%3Apageviews%2Cga%3AtimeOnPage' +
'&filters=ga%3ApagePath%3D%40training%2F' +
'&sort=-ga%3Apageviews' +
'&start-date=2010-01-01' +
'&end-date=2010-01-31'
var gaa = new Packages.com.folderpath.google.analytics.AnalyticsServiceAda pter();
stock = gaa.doQuery(myUrl);
Then, in the fetch script we have:
if (typeof stock == "undefined"){
return (false);
}
var myObject = eval('(' + stock + ')');
if (typeof myObject == "undefined"){
return (false);
}
if ('entries' in myObject && typeof myObject.entries.length == 'undefined'){
var totCount = 1;
if(count < totCount){
row["Date"] = myObject.entries.dimensions[0].value;
row["RealDate"] = row["Date"].substring(0, 4) + '-' + row["Date"].substring(4,6) + '-' + row["Date"].substring(6,8);
row["ContentPath"] = myObject.entries.dimensions[1].value;
row["Country"] = myObject.entries.dimensions[2].value;
row["Region"] = myObject.entries.dimensions[3].value;
row["ContentViews"] = myObject.entries.metrics[0].value;
row["TimeOnContent"] = myObject.entries.metrics[1].value;
count++;
return(true);
}
}
else
if ('entries' in myObject){
var totCount = myObject.entries.length;
if(count < totCount){
row["Date"] = myObject.entries[count].dimensions[0].value;
row["RealDate"] = row["Date"].substring(0, 4) + '-' + row["Date"].substring(4,6) + '-' + row["Date"].substring(6,8);
row["ContentPath"] = myObject.entries[count].dimensions[1].value;
row["Country"] = myObject.entries[count].dimensions[2].value;
row["Region"] = myObject.entries[count].dimensions[3].value;
row["ContentViews"] = myObject.entries[count].metrics[0].value;
row["TimeOnContent"] = myObject.entries[count].metrics[1].value;
count++;
return (true);
}
}
return (false);
I hope this helps.
|
|
|
Re: Exception in Birt while loading class in Google Analytics client library [message #667612 is a reply to message #667596] |
Fri, 29 April 2011 18:02   |
Eclipse User |
|
|
|
Thanks Meghan. This is good information.
On 4/29/2011 4:12 PM, Meghan wrote:
> We actually got this working.
>
> We downloaded the following jars:
> gdata-analytics-2.1
> gdata-analytics-meta-2.1
> gdata-client-1.0
> gdata-client-meta-1.0
> gdata-core-1.0
> google-collect-1.0-rc1
>
> The class files were unpacked and stored in the plugin folder of our
> Eclipse directory. My path looks like this:
>
> C:\Eclipse\eclipse\plugins\org.eclipse.birt.report.viewer_2.
> 6.1.v20100913\birt\WEB-INF\classes\com\google\gdata
>
> We've also created another directory under classes\com\[remainingpath]
> that stores the following class files:
>
> AnalyticsServiceAdapter.class, PriorityFutureTask.class,
> ThrottledPriorityBlockingQueue.class, and UsageData.class
>
> It is this set of class files that is referenced by our data set.
>
> in the data set open event we have code like this:
>
> count = 0;
> var myUrl = 'https://www.google.com/analytics/feeds/data' +
> // this is your google account ID
> '?ids=ga%##### +
> '&dimensions=ga%3Adate%2Cga%3ApagePath' +
> '%2Cga%3Acountry' + '%2Cga%3Aregion' +
> '&metrics=ga%3Apageviews%2Cga%3AtimeOnPage' +
> '&filters=ga%3ApagePath%3D%40training%2F' + '&sort=-ga%3Apageviews' +
> '&start-date=2010-01-01' +
> '&end-date=2010-01-31'
> var gaa = new
> Packages.com.folderpath.google.analytics.AnalyticsServiceAda pter();
>
> stock = gaa.doQuery(myUrl);
>
> Then, in the fetch script we have:
>
> if (typeof stock == "undefined"){
> return (false);
> }
> var myObject = eval('(' + stock + ')');
> if (typeof myObject == "undefined"){
> return (false);
> }
>
>
> if ('entries' in myObject && typeof myObject.entries.length ==
> 'undefined'){
>
> var totCount = 1;
>
>
> if(count < totCount){
> row["Date"] = myObject.entries.dimensions[0].value;
> row["RealDate"] = row["Date"].substring(0, 4) + '-' +
> row["Date"].substring(4,6) + '-' + row["Date"].substring(6,8);
> row["ContentPath"] = myObject.entries.dimensions[1].value;
> row["Country"] = myObject.entries.dimensions[2].value;
> row["Region"] = myObject.entries.dimensions[3].value;
> row["ContentViews"] = myObject.entries.metrics[0].value;
> row["TimeOnContent"] = myObject.entries.metrics[1].value;
> count++;
> return(true);
> }
> }
> else
>
>
> if ('entries' in myObject){
>
> var totCount = myObject.entries.length;
>
>
> if(count < totCount){
> row["Date"] = myObject.entries[count].dimensions[0].value;
> row["RealDate"] = row["Date"].substring(0, 4) + '-' +
> row["Date"].substring(4,6) + '-' + row["Date"].substring(6,8);
> row["ContentPath"] = myObject.entries[count].dimensions[1].value;
> row["Country"] = myObject.entries[count].dimensions[2].value;
> row["Region"] = myObject.entries[count].dimensions[3].value;
> row["ContentViews"] = myObject.entries[count].metrics[0].value;
> row["TimeOnContent"] = myObject.entries[count].metrics[1].value;
> count++;
> return (true);
> }
> }
>
> return (false);
>
> I hope this helps.
>
|
|
|
Re: Exception in Birt while loading class in Google Analytics client library [message #667633 is a reply to message #667612] |
Sat, 30 April 2011 04:07   |
Eclipse User |
|
|
|
Hi all,
Meghan, thank you for this solution but i got some questions:
- Where did you put those jars? classpath, scriptlib, WEB-INF/lib,Report Design -> Property Editor -> Jar Files (which one or ones?)
- I think you created those classes,com,google,data directories and also for your depending classes that other directory, am i right?
- If you already referenced ga api libraries, why did you placed AnalyticsServiceAdapter.class under WEB-INF too?
In my side, i have some news too!
i created a bug form for the birt application and this issue. can be found;
https://bugs.eclipse.org/bugs/show_bug.cgi?id=344239
I received a patch for the URLClassLoader.java from the birt team. I applied it and it worked for me. I don't have anymore problems on this issue. That may help you too.
(The patch and the solution is in that link)
Thank you one more time Meghan and Jason for all your effort.
Ciao!
Jason Weathersby wrote on Sat, 30 April 2011 00:02 | Thanks Meghan. This is good information.
On 4/29/2011 4:12 PM, Meghan wrote:
> We actually got this working.
>
> We downloaded the following jars:
> gdata-analytics-2.1
> gdata-analytics-meta-2.1
> gdata-client-1.0
> gdata-client-meta-1.0
> gdata-core-1.0
> google-collect-1.0-rc1
>
> The class files were unpacked and stored in the plugin folder of our
> Eclipse directory. My path looks like this:
>
> C:\Eclipse\eclipse\plugins\org.eclipse.birt.report.viewer_2.
> 6.1.v20100913\birt\WEB-INF\classes\com\google\gdata
>
> We've also created another directory under classes\com\[remainingpath]
> that stores the following class files:
>
> AnalyticsServiceAdapter.class, PriorityFutureTask.class,
> ThrottledPriorityBlockingQueue.class, and UsageData.class
>
> It is this set of class files that is referenced by our data set.
>
> in the data set open event we have code like this:
>
> count = 0;
> var myUrl = 'https://www.google.com/analytics/feeds/data' +
> // this is your google account ID
> '?ids=ga%##### +
> '&dimensions=ga%3Adate%2Cga%3ApagePath' +
> '%2Cga%3Acountry' + '%2Cga%3Aregion' +
> '&metrics=ga%3Apageviews%2Cga%3AtimeOnPage' +
> '&filters=ga%3ApagePath%3D%40training%2F' + '&sort=-ga%3Apageviews' +
> '&start-date=2010-01-01' +
> '&end-date=2010-01-31'
> var gaa = new
> Packages.com.folderpath.google.analytics.AnalyticsServiceAda pter();
>
> stock = gaa.doQuery(myUrl);
>
> Then, in the fetch script we have:
>
> if (typeof stock == "undefined"){
> return (false);
> }
> var myObject = eval('(' + stock + ')');
> if (typeof myObject == "undefined"){
> return (false);
> }
>
>
> if ('entries' in myObject && typeof myObject.entries.length ==
> 'undefined'){
>
> var totCount = 1;
>
>
> if(count < totCount){
> row["Date"] = myObject.entries.dimensions[0].value;
> row["RealDate"] = row["Date"].substring(0, 4) + '-' +
> row["Date"].substring(4,6) + '-' + row["Date"].substring(6,8);
> row["ContentPath"] = myObject.entries.dimensions[1].value;
> row["Country"] = myObject.entries.dimensions[2].value;
> row["Region"] = myObject.entries.dimensions[3].value;
> row["ContentViews"] = myObject.entries.metrics[0].value;
> row["TimeOnContent"] = myObject.entries.metrics[1].value;
> count++;
> return(true);
> }
> }
> else
>
>
> if ('entries' in myObject){
>
> var totCount = myObject.entries.length;
>
>
> if(count < totCount){
> row["Date"] = myObject.entries[count].dimensions[0].value;
> row["RealDate"] = row["Date"].substring(0, 4) + '-' +
> row["Date"].substring(4,6) + '-' + row["Date"].substring(6,8);
> row["ContentPath"] = myObject.entries[count].dimensions[1].value;
> row["Country"] = myObject.entries[count].dimensions[2].value;
> row["Region"] = myObject.entries[count].dimensions[3].value;
> row["ContentViews"] = myObject.entries[count].metrics[0].value;
> row["TimeOnContent"] = myObject.entries[count].metrics[1].value;
> count++;
> return (true);
> }
> }
>
> return (false);
>
> I hope this helps.
>
|
[Updated on: Sat, 30 April 2011 04:08] by Moderator
|
|
|
|
|
|
|
|
|
|
|