Share
Embed
Analytics in an Aspect Oriented manner V2.0
The presentation took place at GDG Android Athens meetup. https://www.meetup.com/GDG-Android-Athens/events/251174805/
Spiros Economakis
June 13, 2018
Transcript
65 slides
-
Why analytics are important? • Help to build an efficient
marketing strategy -
Why analytics are important? • Help to build an efficient
marketing strategy • Measure performance of the features -
Why analytics are important? • Help to build an efficient
marketing strategy • Measure performance of the features • Measure retention of the users -
Why analytics are important? • Help to build an efficient
marketing strategy • Measure performance of the features • Measure retention of the users • Optimise flow processes/funnels -
More tracking, more code @OnClick(R.id.signUpBtn) fun signUpClicked() { KISSmetricsAPI.sharedAPI().record("signupStartEvent") FirebaseAnalytics.getInstance(this).logEvent("signupStartEvent",
null) Answers.getInstance().logCustom(CustomEvent("signupStartEvent")) AppEventsLogger.newLogger(this).logEvent("signupStartEvent") } -
More tracking, more code @OnClick(R.id.signUpBtn) fun signUpClicked() { KISSmetricsAPI.sharedAPI().record("signupStartEvent") FirebaseAnalytics.getInstance(this).logEvent("signupStartEvent",
null) Answers.getInstance().logCustom(CustomEvent("signupStartEvent")) AppEventsLogger.newLogger(this).logEvent("signupStartEvent") } -
More tracking, more code @OnClick(R.id.signUpBtn) fun signUpClicked() { KISSmetricsAPI.sharedAPI().record("signupStartEvent") FirebaseAnalytics.getInstance(this).logEvent("signupStartEvent",
null) Answers.getInstance().logCustom(CustomEvent("signupStartEvent")) AppEventsLogger.newLogger(this).logEvent("signupStartEvent") } -
Tracking event @OnClick(R.id.signUpBtn) fun signUpClicked() { KISSmetricsAPI.sharedAPI().record("signupStartEvent") FirebaseAnalytics.getInstance(this).logEvent("signupStartEvent", null) Answers.getInstance().logCustom(CustomEvent(“signupStartEvent"))
AppEventsLogger.newLogger(this).logEvent("signupStartEvent") } -
Tracking with data private val stateObserver = Observer<SignUpViewState> { state
-> state.let { when (state) { is SignUpSuccessViewState -> { this.renderSuccess(state.user) } } } } -
Tracking with data private fun renderSuccess(user: UserViewModel) { val trackingData
= mapOf("id" to user.id, "name" to user.fulName) KISSmetricsAPI.sharedAPI().record("signupSuccess", trackingData) Answers.getInstance().logSignUp(SignUpEvent().putSuccess(true)) val trackingBundle = Bundle().apply { putString("id", user.id) putString("name", user.fulName) } FirebaseAnalytics.getInstance(this).logEvent("signupSuccess", trackingBundle) AppEventsLogger.newLogger(this).logEvent("signupSuccess", trackingBundle) } -
More tracking data, more code private fun renderSuccess(user: UserViewModel)
{ val trackingData = mapOf("id" to user.id, "name" to user.fulName) KISSmetricsAPI.sharedAPI().record("signupSuccess", trackingData) Answers.getInstance().logSignUp(SignUpEvent().putSuccess(true)) val trackingBundle = Bundle().apply { putString("id", user.id) putString("name", user.fulName) } FirebaseAnalytics.getInstance(this).logEvent("signupSuccess", trackingBundle) AppEventsLogger.newLogger(this).logEvent("signupSuccess", trackingBundle) } -
More tracking data, more code private fun renderSuccess(user: UserViewModel)
{ val trackingData = mapOf("id" to user.id, "name" to user.fulName) KISSmetricsAPI.sharedAPI().record("signupSuccess", trackingData) Answers.getInstance().logSignUp(SignUpEvent().putSuccess(true)) val trackingBundle = Bundle().apply { putString("id", user.id) putString("name", user.fulName) } FirebaseAnalytics.getInstance(this).logEvent("signupSuccess", trackingBundle) AppEventsLogger.newLogger(this).logEvent("signupSuccess", trackingBundle) } -
Hide - Singleton object AnalyticsTracker { fun initialise(ctx: Context) {
//initialise tools } fun log(event: String) { //all tools to track } fun log(event: String, data: Map<String, Any>) { //all tools to track } } -
Hide - Singleton private fun renderSuccess(user: UserViewModel) { val trackingData
= mapOf("id" to user.id, "name" to user.fulName) AnalyticsTracker.log("signupSuccess", trackingData) } -
Composition class TrackingDelegator constructor(ctx: Context) { fun onSignUpClicked() { //all
tools to track } fun onSignUpSuccess(user: UserViewModel) { //all tools to track } } -
Tracking is a Cross-Cutting Concern The concerns representing functionalities for
secondary requirements are referred to as crosscutting concerns or system-wide concerns. -
Definition Aspect-oriented programming entails breaking down program logic into "concerns".
This means, that with AOP, we can add executable blocks to some source code without explicitly changing it. This programming paradigm pretends that “cross-cutting concerns” should be implemented once and injected it many times into those places. -
Terminology Join point: Join points are points in the execution
of the system, such as method calls or method entry Pointcut: An expression which tells a code injection tool where to inject a particular piece of code eg. to which join points to apply a particular advice. Advice: The code that is injected to a class file. Typically we talk about before, after, and around advices, which are executed before, after, or instead of a target method. -
Terminology Join point: Join points are points in the execution
of the system, such as method calls or method entry Pointcut: An expression which tells a code injection tool where to inject a particular piece of code eg. to which join points to apply a particular advice. Advice: The code that is injected to a class file. Typically we talk about before, after, and around advices, which are executed before, after, or instead of a target method. -
Terminology Join point: Join points are points in the execution
of the system, such as method calls or method entry Pointcut: An expression which tells a code injection tool where to inject a particular piece of code eg. to which join points to apply a particular advice. Advice: The code that is injected to a class file. Typically we talk about before, after, and around advices, which are executed before, after, or instead of a target method. -
Terminology Aspect: The combination of the pointcut and the advice
is termed an aspect. For instance, we add a tracking aspect to our application by defining a pointcut and giving the correct advice. Weaving: The process of injecting code – advices – into the target places – join points. -
Terminology Aspect: The combination of the pointcut and the advice
is termed an aspect. For instance, we add a tracking aspect to our application by defining a pointcut and giving the correct advice. Weaving: The process of injecting code – advices – into the target places – join points. -
Pointcuts with Annotations @TrackEvent - constructor & method @TrackEventAttribute -
method params only @TrackStaticAttribute - method params only -
Pointcuts with Annotations @TrackEvent - constructor & method @TrackEventAttribute -
method params only @TrackStaticAttribute - method params only -
Pointcuts with Annotations @TrackEvent - constructor & method @TrackEventAttribute -
method params only @TrackStaticAttribute - method params only -
Aspect @Aspect class TrackEventAspect { @Pointcut("execution(@com.clueso.tracking.annotation.TrackEvent * *(..))") fun methodAnnotatedWithTrackEvent()
{ } @Pointcut("execution(@com.clueso.tracking.annotation.TrackEvent *.new(..))") fun constructorAnnotatedTrackEvent() { } @Around("methodAnnotatedWithTrackEvent() || constructorAnnotatedTrackEvent()") @Throws(Throwable::class) fun weaveJoinPointTrackEvent(joinPoint: ProceedingJoinPoint): Any { } } -
Aspect @Aspect class TrackEventAspect { @Pointcut("execution(@com.clueso.tracking.annotation.TrackEvent * *(..))") fun methodAnnotatedWithTrackEvent()
{ } @Pointcut("execution(@com.clueso.tracking.annotation.TrackEvent *.new(..))") fun constructorAnnotatedTrackEvent() { } @Around("methodAnnotatedWithTrackEvent() || constructorAnnotatedTrackEvent()") @Throws(Throwable::class) fun weaveJoinPointTrackEvent(joinPoint: ProceedingJoinPoint): Any { } } -
Aspect @Aspect class TrackEventAspect { @Pointcut("execution(@com.clueso.tracking.annotation.TrackEvent * *(..))") fun methodAnnotatedWithTrackEvent()
{ } @Pointcut("execution(@com.clueso.tracking.annotation.TrackEvent *.new(..))") fun constructorAnnotatedTrackEvent() { } @Around("methodAnnotatedWithTrackEvent() || constructorAnnotatedTrackEvent()") @Throws(Throwable::class) fun weaveJoinPointTrackEvent(joinPoint: ProceedingJoinPoint): Any { } } -
Aspect @Aspect class TrackEventAspect { @Pointcut("execution(@com.clueso.tracking.annotation.TrackEvent * *(..))") fun methodAnnotatedWithTrackEvent()
{ } @Pointcut("execution(@com.clueso.tracking.annotation.TrackEvent *.new(..))") fun constructorAnnotatedTrackEvent() { } @Around("methodAnnotatedWithTrackEvent() || constructorAnnotatedTrackEvent()") @Throws(Throwable::class) fun weaveJoinPointTrackEvent(joinPoint: ProceedingJoinPoint): Any { } } -
Tracking Adapters class AnswersTrackingAdapter : TrackAdapter { override fun track(event:
TrackEvent, attributes: Map<String, Any>) { //tracking } } -
Tracking Adapters class AnswersTrackingAdapter : TrackAdapter { override fun track(event:
TrackEvent, attributes: Map<String, Any>) { //tracking } } -
Create Clueso val answersAdapter = AnswersTrackingAdapter() val firebaseAdapter = FirebaseTrackingAdapter()
Clueso.create { isDebuggable = true adapters = listOf(answersAdapter, firebaseAdapter) } -
Create Clueso val answersAdapter = AnswersTrackingAdapter() val firebaseAdapter = FirebaseTrackingAdapter()
Clueso.create { isDebuggable = true adapters = listOf(answersAdapter, firebaseAdapter) } -
Polyglot AOP AOP within the language, or as an external
library: • Python • Haskell • Ruby • Swift • Lua • Delphi -
Conclusion • Enhance SRP of the SOLID principles • Clean,
readable and reusable code -
Conclusion • Enhance SRP of the SOLID principles • Clean,
readable and reusable code • Increases modularity -
Conclusion • Enhance SRP of the SOLID principles • Clean,
readable and reusable code • Increases modularity • Testable code -
Conclusion • Enhance SRP of the SOLID principles • Clean,
readable and reusable code • Increases modularity • Testable code • Build or load time code injection. Source-code weaving