项目作者: programmerr47

项目描述 :
Analytics library preferably sharpened for Google Analytics
高级语言: Kotlin
项目地址: git://github.com/programmerr47/ganalytics.git
创建时间: 2017-04-01T19:53:29Z
项目社区:https://github.com/programmerr47/ganalytics

开源协议:MIT License

下载


Overview

Download

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

Here is latest changelog.

Also, you can read these articles for more details:
1) @programmerr47/declarative-analytics-ganalytics-4cb927b98be8">Introduction to conception
2) @programmerr47/effective-application-analytic-832f950232b9">V1.1 Changelog details

Get library

With gradle:

  1. compile 'com.github.programmerr47:ganalytics-core:1.1.0'

With maven:

  1. <dependency>
  2. <groupId>com.github.programmerr47</groupId>
  3. <artifactId>ganalytics-core</artifactId>
  4. <version>1.1.0</version>
  5. <type>pom</type>
  6. </dependency>

Basic Usage

To start with gathering analytics:

  1. Create an group or category interface and fill it with necessary annotations:

    1. @Prefix
    2. interface CategoryInterface {
    3. fun action()
    4. @NoPrefix fun otherAction(@Label(LabelConverter::class) String label)
    5. }

    or

    1. interface GroupInterface {
    2. @Prefix fun category(): CategoryInterface
    3. @Convention(NamingConventions.LOWER_CAMEL_CASE) fun otherCategory(): OtherCategoryInterface
    4. }

    For more information about interfaces and annotations read linked sections.

  2. Prepare Ganalytics instance through:

For group interfaces:

  1. val ganalytics = Ganalytics({ System.out.println(it) /**or do something with received incoming events**/ }) {
  2. cutOffAnalyticsClassPrefix = false
  3. prefixSplitter = "_"
  4. namingConvention = NamingConventions.LOWER_SNAKE_CASE
  5. labelTypeConverters += TypeConverterPair<DummyDataClass> { it.name } +
  6. TypeConverterPair<DummyReversedClass> { it.id.toString() }
  7. }

wich is equal to:

  1. val ganalytics = GanalyticsSettings {
  2. cutOffAnalyticsClassPrefix = false
  3. prefixSplitter = "_"
  4. namingConvention = NamingConventions.LOWER_SNAKE_CASE
  5. labelTypeConverters += TypeConverterPair<DummyDataClass> { it.name } +
  6. TypeConverterPair<DummyReversedClass> { it.id.toString() }
  7. }.createGroup { System.out.println(it) /**or do something with received incoming events**/ }

For category interfaces:

  1. val ganalytics = GanalyticsSettings {
  2. cutOffAnalyticsClassPrefix = false
  3. prefixSplitter = "_"
  4. namingConvention = NamingConventions.LOWER_SNAKE_CASE
  5. labelTypeConverters += TypeConverterPair<DummyDataClass> { it.name } +
  6. TypeConverterPair<DummyReversedClass> { it.id.toString() }
  7. }.createSingle { System.out.println(it) /** or do something with received incoming events**/ }
  1. Pass an interface class to ganalytics:

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

  1. Now you can use analytics. For example:

analytics.category().otherAction("label")

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

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

  1. googleAnalyticsTracker.send(HitBuilders.EventBuilder()
  2. .setCategory(it.category)
  3. .setAction(it.action)
  4. .setLabel(it.label)
  5. .setValue(it.value)
  6. .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.