How can we know the Application Usage when we publish the application to the store? Of course, like appstore or marketplace, members will be given a background. After logging on, you can see the app downloads and installation volumes. However, it seems that the statistics are based on the previous week, and the statistics can be said in the past, data analysis? Of course, there are also some third-party statistical analysis tools; Google Analytics may already be familiar to everyone. It mainly provides free enterprise website analysis services, statistical analysis of website traffic and various promotion effects; you can view the statistical report in multiple dimensions. Of course, it also provides the Mobile Tracking Service (I have not learned how to use it). Can we use it to help us collect statistics on mobile applications? Of course, the answer is yes;
Preface
Google Analytics is used in Windows phone7, provided that it is based on the msaf (Microsoft Silverlight analytics framework) framework, which is provided by Microsoft for Microsoft Silverlight, WPF, windows Phone 7 web statistics framework. The framework supports the following analysis for each platform:
You can study this framework again.
At the same time, you can download the sl5 & WP7 sample in the download option. I'm glad that the WP7 sample here uses Google Analytics and provides encapsulated Google. webanalytics. DLL. Let's take a look. You can use reflector.Code, Which encapsulates the call to the Google Analytics interface;
The main implementation is that analytics (including googleanalytics and consoleanalytics) is based on behavior, and other user behaviors (such as clicking a button, rolling panorama view, and switching pivot controls) are based on triggeraction ); in this way, you can add the triggers action of the corresponding control where you need to capture user operations;
For the startup, shutdown, and activation of applications in Microsoft. webanalytics. capture Microsoft. phone. shell. the activated, closing, deactivated, and launching events of phoneapplicationservice are written or saved to the log file or remote platform (Google Analytics) by the Data Collector datacollector );
For page access statistics, the navigated event of phoneapplicationframe is captured in Microsoft. webanalytics. webanalyticsservice and then recorded by the data collector;
The above is a brief understanding of msaf for WP7 to help you understand it;
Before using the service, you must go to http://www.google.com/analytics/ to open the function, because it is the tracking ID in the Google Analytics account used for statistical analysis in the application;
1. Find the DLL to be referenced and copy the DLL files from the bin directory of the testapp. WP7 project of msaf WP7.
2. Create a Windows phone7 Project
3. Add DLL references. Create the Lib folder in the same directory of the googleanalytics4wp7 project solution, copy the DLL in middle to Lib, and add references to these DLL in the googleanalytics4wp7 project.
4. Add the analyticsservice class to enable msaf
View code
Using System; Using System. net; Using System. windows; Using System. Windows. controls; Using System. Windows. documents; Using System. Windows. Ink; Using System. Windows. input; Using System. Windows. Media; Using System. Windows. Media. animation; Using System. Windows. shapes; Using Google. webanalytics; Using Microsoft. webanalytics; Using System. componentmodel. Composition. Hosting; Using Microsoft. webanalytics. behaviors; Namespace Googleanalytics4wp7 { Public Class Analyticsservice: iapplicationservice { # Region Iapplicationservice members Public Void Startservice (applicationservicecontext context) {compositionhost. initialize ( New Assemblycatalog (application. Current. GetType (). Assembly ), New Assemblycatalog ( Typeof (Microsoft. webanalytics. analyticsevent). Assembly ), New Assemblycatalog ( Typeof (Microsoft. webanalytics. behaviors. trackaction). Assembly ), New Assemblycatalog (Typeof (Googleanalytics). Assembly ));} Public Void Stopservice (){} # Endregion }}
5. initialize analyticsservice in APP. XAML
View code
< Application X: Class = " Googleanalytics4wp7. app " Xmlns = " Http://schemas.microsoft.com/winfx/2006/xaml/presentation " Xmlns: x = " Http://schemas.microsoft.com/winfx/2006/xaml " Xmlns: Phone = " CLR-namespace: Microsoft. Phone. controls; Assembly = Microsoft. Phone " Xmlns: Shell = " CLR-namespace: Microsoft. Phone. Shell; Assembly = Microsoft. Phone " Xmlns: I = " CLR-namespace: system. Windows. interactivity; Assembly = system. Windows. Interactivity " Xmlns: MWA = " CLR-namespace: Microsoft. webanalytics; Assembly = Microsoft. webanalytics " Xmlns: GA = " CLR-namespace: Google. webanalytics; Assembly = Google. webanalytics " Xmlns: Local = " CLR-namespace: googleanalytics4wp7 " > <! -- Application resources --> <application. Resources> </application. Resources> <application. applicationlifetimeobjects> <! -- Required Object That handles Lifetime Events For The Application --> < Shell: phoneapplicationservice launching =" Application_launching " Closing = " Application_closing " Activated = " Application_activated " Deactivated = " Application_deactivated " /> <Local: analyticsservice> </local: analyticsservice> <MWA: webanalyticsservice. Services> <GA: googleanalytics webpropertyid = "" Category = " Wp75 " /> </MWA: webanalyticsservice. Services> </MWA: webanalyticsservice> </application. applicationlifetimeobjects> </Application>
6. Add a page navigation; add a button in mainpage and navigate to the new testpage. XAML page in its click event;
Private VoidButton#click (ObjectSender, routedeventargs e ){This. Navigationservice. navigate (NewUri ("/Testpage. XAML", Urikind. Relative ));}
RunProgram, Click the button and view the page access statistics in the Google Analytics real-time => content statistics window
The preceding figure shows simple page access statistics. You can also go to [standard report]> [content] => [event] to view event statistics;
Add event statistics:
Add a trigger to the button in mainpage. XAML.
<Button content = " Button " Height = " 72 " Horizontalalignment = " Left " Margin = " 124,117, 0, 0 " Name = " Button1 " Verticalalignment = " Top " Width = " 160 " Click = " Button#click " > <I: interaction. triggers> <I: eventtrigger eventname = " Click " > <MWAB: trackaction X: Name = " Button1 " /> </I: eventtrigger> </I: interaction. triggers> </button>
In this way, the events in the Google Analytics statistics result will have the corresponding number of clicks;
The statistics of other control events are also based on triggers, which have been introduced at the beginning;
With the statistical results, you can view the number of currently used applications in real time in the Google Analytics report, count the number of times users start and close, and view users' usage habits through the number of page visits;
Is it helpful for your application? :)
Instance code