Integrating Google Analytics      in Android apps         +Franklin van Velthuizen              @FranklinNL       f.vanvel...
Who am I?
Agenda• Basic integration • Pageviews, events, ...• Take it a step further• Legal stuff
Why use GA?• Free• Highly used among a variety of disciplines• Additional APIs• Powerful platform• Downside: lack of SDK d...
Agenda• Basic integration • Pageviews, events, ...• Take it a step further• Legal stuff
Let’s start!• Download the SDK at  http://code.google.com/mobile/analytics• Add the JAR to your build path• Add the requir...
The tracker objectprivate GoogleAnalyticsTracker tracker;...tracker = GoogleAnalyticsTracker.getInstance();tracker.startNe...
What can we track?     Activity viewed by a user        PageviewInteraction with interface elements    Event
Tracking pageviews(See example project GA Demo v1.)
Tracking pageviews
Dispatching• Manual dispatch vs automatic dispatch  tracker.startNewSession(“UA-..., context);  tracker.startNewSession(“U...
Tracking events(See example project GA Demo v2.)
Tracking events
Tracking custom vars Three-level visitor interaction model
Tracking custom vars Three-level visitor interaction model                               Visitor
Tracking custom vars Three-level visitor interaction model                               Visitor                          ...
Tracking custom vars Three-level visitor interaction model                               Visitor                          ...
Tracking custom vars Three-level visitor interaction model                               Visitor                          ...
Tracking custom vars
Tracking custom vars(See example project GA Demo v3.)
A/B testingprivate static final boolean isA =UUID.randomUUID().getLeastSignificantBits() % 2 == 0;...if(isA) {  setContent...
Ecommerce tracking• Add a transaction• Add items to the transaction• Send the transaction to the dispatcher
Ecommerce tracking(See example project GA Demo v4.)
Ecommerce tracking
Campaign tracking• Android Market campaigns • Campaigns using QR codes on bill boards• General campaign tracking • Links i...
Agenda• Basic integration • Pageviews, events, ...• Take it a step further• Legal stuff
Take it a step further• onCreate and onDestroy yield long visits• Same for onStart and onStop• onResume and onPause yield ...
Analytics wrapper class• Use my Analytics wrapper class (and  improve it)• Sessions are stopped in a delayed way using  a ...
Agenda• Basic integration • Pageviews, events, ...• Take it a step further• Legal stuff
Legal stuff• Always inform your users• If feasible, provide an opt-out possibility• Use setAnonymizeIp
Resources• Mobile Developer Documentation (sparse!)  http://code.google.com/mobile/analytics• Google Analytics Developer d...
Upcoming SlideShare
Loading in …5
×

Integrating Google Analytics in Android apps

4,213 views

Published on

Published in: Technology, News & Politics
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,213
On SlideShare
0
From Embeds
0
Number of Embeds
522
Actions
Shares
0
Downloads
58
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • Management API, Data Export API\n
  • \n
  • \n
  • UA = website profile ID\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • Page = Pageviews and Events\nAlways set your custom var before generating a pageview or event\nExamples: Paid user; Logged in user/Network type; Sections in news app\n
  • \n
  • \n
  • Downside: you need to push an update to start A/B testing\n
  • Transactions and items generate individual hits\n
  • \n
  • \n
  • \n
  • \n
  • - strange visits when switching between activities\n
  • Class composition\n
  • \n
  • Opt-out downside: existing data will not be removed\nsetAnonymizeIp removes the last octet of IP addresses\nEULA is supposed to protect you, instead of gaining permission\n\n
  • \n
  • Integrating Google Analytics in Android apps

    1. 1. Integrating Google Analytics in Android apps +Franklin van Velthuizen @FranklinNL f.vanvelthuizen@colours.nl
    2. 2. Who am I?
    3. 3. Agenda• Basic integration • Pageviews, events, ...• Take it a step further• Legal stuff
    4. 4. Why use GA?• Free• Highly used among a variety of disciplines• Additional APIs• Powerful platform• Downside: lack of SDK documentation ...
    5. 5. Agenda• Basic integration • Pageviews, events, ...• Take it a step further• Legal stuff
    6. 6. Let’s start!• Download the SDK at http://code.google.com/mobile/analytics• Add the JAR to your build path• Add the required permissions to your manifest• Sign up at http://www.google.com/analytics• Create an account and profile
    7. 7. The tracker objectprivate GoogleAnalyticsTracker tracker;...tracker = GoogleAnalyticsTracker.getInstance();tracker.startNewSession(“UA-...”, context);...tracker.stopSession();Google says: “In onCreate and onDestroy”but that has implications.
    8. 8. What can we track? Activity viewed by a user PageviewInteraction with interface elements Event
    9. 9. Tracking pageviews(See example project GA Demo v1.)
    10. 10. Tracking pageviews
    11. 11. Dispatching• Manual dispatch vs automatic dispatch tracker.startNewSession(“UA-..., context); tracker.startNewSession(“UA-...”, 10, context);• Batches of max 30 hits in manual mode• Try to bundle your dispatches
    12. 12. Tracking events(See example project GA Demo v2.)
    13. 13. Tracking events
    14. 14. Tracking custom vars Three-level visitor interaction model
    15. 15. Tracking custom vars Three-level visitor interaction model Visitor
    16. 16. Tracking custom vars Three-level visitor interaction model Visitor Session
    17. 17. Tracking custom vars Three-level visitor interaction model Visitor Session
    18. 18. Tracking custom vars Three-level visitor interaction model Visitor Session Page
    19. 19. Tracking custom vars
    20. 20. Tracking custom vars(See example project GA Demo v3.)
    21. 21. A/B testingprivate static final boolean isA =UUID.randomUUID().getLeastSignificantBits() % 2 == 0;...if(isA) { setContentView(R.layout.A); tracker.trackPageView(“/HomeActivity/A”);} else { setContentView(R.layout.B); tracker.trackPageView(“/HomeActivity/B”);}
    22. 22. Ecommerce tracking• Add a transaction• Add items to the transaction• Send the transaction to the dispatcher
    23. 23. Ecommerce tracking(See example project GA Demo v4.)
    24. 24. Ecommerce tracking
    25. 25. Campaign tracking• Android Market campaigns • Campaigns using QR codes on bill boards• General campaign tracking • Links in online advertisements
    26. 26. Agenda• Basic integration • Pageviews, events, ...• Take it a step further• Legal stuff
    27. 27. Take it a step further• onCreate and onDestroy yield long visits• Same for onStart and onStop• onResume and onPause yield multiple visits
    28. 28. Analytics wrapper class• Use my Analytics wrapper class (and improve it)• Sessions are stopped in a delayed way using a delayed Runnable
    29. 29. Agenda• Basic integration • Pageviews, events, ...• Take it a step further• Legal stuff
    30. 30. Legal stuff• Always inform your users• If feasible, provide an opt-out possibility• Use setAnonymizeIp
    31. 31. Resources• Mobile Developer Documentation (sparse!) http://code.google.com/mobile/analytics• Google Analytics Developer docs http://code.google.com/apis/analytics/docs/• Example code http://www.yoki.org/droidconNL/droidconNL.zip

    ×