Skip to content

Analytics library preferably sharpered for Google Analytics

License

Notifications You must be signed in to change notification settings

naseemakhtar994/ganalytics

 
 

Repository files navigation

Overview

Download

Ganalytics is tiny api layer for any analytics in application. It provides object oriented, typesafe, stricked and testable way for organize work with analytics through the application. More information on wiki pages.

Here is latest changelog.

Get library

With gradle:

compile 'com.github.programmerr47:ganalytics-core:1.0.0'

With maven:

<dependency>
  <groupId>com.github.programmerr47</groupId>
  <artifactId>ganalytics-core</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

Basic Usage

To start with gathering analytics:

  1. Create an group or category interface and fill it with necessary annotations:
@Prefix
interface SampleInterface {
    fun method1()
    @NoPrefix fun method1(@Label(LabelConverter::class) String label)
}

or

interface SampleGroupInterface {
    @Prefix fun sampleInterface(): SampleInterface
    @Convention(NamingConventions.LOWER_CAMEL_CASE) fun anotherInterface(): AnotherInterface
}

For more information about interfaces and annotations read linked sections.

  1. Prepare Ganalytics instance through:

For group interfaces:

val ganalytics = Ganalytics({ System.out.print(it) }) {
     cutOffAnalyticsClassPrefix = false
     prefixSplitter = "_"
     namingConvention = NamingConventions.LOWER_SNAKE_CASE
     labelTypeConverters += TypeConverterPair<DummyDataClass> { it.name } +
             TypeConverterPair<DummyReversedClass> { it.id.toString() } 
}

wich is equal to:

val ganalytics = GanalyticsSettings {
    cutOffAnalyticsClassPrefix = false
    prefixSplitter = "_"
    namingConvention = NamingConventions.LOWER_SNAKE_CASE
    labelTypeConverters += TypeConverterPair<DummyDataClass> { it.name } +
            TypeConverterPair<DummyReversedClass> { it.id.toString() }
}.createGroup { System.out.print(it) }

For category interfaces:

val ganalytics = GanalyticsSettings {
    cutOffAnalyticsClassPrefix = false
    prefixSplitter = "_"
    namingConvention = NamingConventions.LOWER_SNAKE_CASE
    labelTypeConverters += TypeConverterPair<DummyDataClass> { it.name } +
            TypeConverterPair<DummyReversedClass> { it.id.toString() }
}.createSingle { System.out.print(it) }
  1. Pass an interface class to ganalytics:

val analytics = ganalytics.create(SampleGroupInterface::class)

  1. Now you can use analytics. For example:

analytics.sampleInterface().method1()

will print to the standart output: Event(category=sampleinterface, action=sampleinterface_method1)

Note: instead of System.out.println you can pass, for example:

googleAnalyticsTracker.send(HitBuilders.EventBuilder()
        .setCategory(it.category)
        .setAction(it.action)
        .setLabel(it.label)
        .setValue(it.value)
        .build())

Or any analytics method as you want.

For more info of basic usage see samples folder in project. Also please visit the wiki pages to know more details.

About

Analytics library preferably sharpered for Google Analytics

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%