问题
Worklight 6.2.0, Mobile Web Environment
The Worklight Info Center offers three formulations for logging an analytic message
WL.Analytics.log('my record');
WL.Analytics.log({data: [1,2,3]});
WL.Analytics.log({data: [1,2,3]}, 'MyData');
I am successfully using the first of these, but the other two produce no analytics and my fail() function is not fired.
I see in the online tutorials a further formulation
WL.Analytics.log({_activity: "myActivity" });
this too produces no output.
Question: Are there other formulations that do work?
回答1:
All calls other than
WL.Analytics.log('my record')
were intended for Analytics features that were not implemented or did not make it into the Worklight 6.2 release. Clearly this is not reflected in the documentation. I will open a defect to either have the logs searchable or have this limitation reflected in the documentation.
If the following call:
WL.Analytics.log({_activity: "myActivity" });
does not result in activities being searchable in the 'Activites' page of the Analytics console, then this is a defect for Worklight 6.2.
I can confirm that all of the above issues are fixed for the next release of Worklight (whether its through code fixes or documentation). If you need some of these fixes backported to a previous release of Worklight, please open a PMR so that we can begin that process.
回答2:
I would suggest passing in the stringify property as true.
var obj = {name : "bob", age : 100};
WL.Logger.config({stringify : true, pkg: 'myActivity'});
WL.Logger.debug(obj);
If you want a pretty format you could pass in the pretty property
WL.Logger.config({stringify : true, pretty : true, pkg: 'myActivity'});
WL.Logger.debug(obj);
Hope this helps.
来源:https://stackoverflow.com/questions/26484559/worklight-analytics-payload