Analytics Manager User Guide
Introduction
The AnalyticsManager
provides a robust and flexible way to track events, like click, swipe, drag and states like loading, error etc in your application. It encapsulates Adobe's Mobile SDK to track and log analytic events.
Classes & Interfaces
OCAdobeAnalyticsService
This class is responsible for tracking of events generated in the host application. All the actions and states are handled by Adobe Analytics. It has methods to log actions, states, and errors via Adobe's SDK.
OCAnalyticsEvent
Defines the skeleton of an analytics event. It includes name of the event, type of the event and the event data.
OCAnalyticsEventType
There are two types of analytic events: State events (like screen load, error etc.) and Action events (like button clicks, scroll, swipe etc.).
OCAnalyticsManager
It acts as a broker in between Analytics service and host Application. It creates events and sends them to the Analytics service. You set global parameters so that these params will be appended in all the analytics events here.
OCAnalyticsService
Defines the skeleton of Analytics Service. It is used by OCAnalyticsManager
to send events.
Usage
Initialize OCAdobeAnalyticsService.initialize(this, "<Adobe_App_ID>", OCAnalyticsLoggingMode.DEBUG)
in your host application.
Define the keys, values and constants that need to pass
object OnboardingAnalytics {
// Keys
object Key {
const val sampleKey = "sampleKey"
}
// Values
object Value {
const val sampleValue = "sampleKey"
}
// Constants
object Constant {
const val sampleConstant = "sampleConstant"
}
}
Define the events you want to track:
sealed class OnboardingAnalyticsEvent: OCAnalyticsEvent {
object OnboardingIntro: OnboardingAnalyticsEvent() {
override val name: String = "onboarding_intro"
override val type: AnalyticsEventType = OCAnalyticsEventType.STATE
override val data: Map<String, Any> = mapOf(
OnboardingAnalytics.Key.sampleKey to OnboardingAnalytics.Value.sampleValue,
"pageTitle" to "onboarding_intro"
)
}
// Define more events similarly ..
fun getCommonProperties() = mapOf(
"aokPageCategory" to "onboarding",
"pageLanguage" to "de",
"pageType" to "onboarding"
)
}
Then, trigger the events from your activity:
class MainActivity : AppCompatActivity() {
@Inject lateinit var analyticsManager: AnalyticsManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
analyticsManager.setCommonProperties(mapOf("age" to "30", "gender" to "male"))
analyticsManager.trackEvent(OnboardingAnalyticsEvent.OnboardingIntro)
}
}
In the example above, OnboardingAnalyticsEvent.OnboardingIntro
is an event subclass which extends from OCAnalyticsEvent
and provides the name
, type
and data
. The data
includes both common data (like aokPageCategory
, pageLanguage
, and pageType
) and event-specific data (like sampleKey
and pageTitle
). These data are then merged with common properties and sent to the Adobe Mobile SDK for processing.