Giter Site home page Giter Site logo

raincoat's Introduction

🧥 Raincoat

Analytics abstraction layer for Kotlin inspired by Umbrella.

Table of Contents

Getting Started

As you can see it is really simple to log with different analytics with a simple function:

val analytics = Raincoat<MyEvent>()
analytics.register(FirebaseProvider(context))
analytics.register(MixpanelProvider(context))
analytics.log(MyEvent.SignUp("username"))

Example

Using Kotlin sealed class we can easily setup all things that we will have to track:

sealed class MyEvent : EventType {

    class SignUp(username: String) : MyEvent()
    class Register(username: String, password: String) : MyEvent()

    override fun name(provider: ProviderType): String? {
        return when (this) {
            is SignUp -> "signUp"
            is Register -> "register"
        }
    }

    override fun parameters(provider: ProviderType): HashMap<String, Any>? {
        return when (this) {
            is SignUp -> {
                hashMapOf()
            }
            is Register -> {
                hashMapOf("username" to this.username, "password" to this.password))
            }
        }
    }
}

Providers

At this very moment we developed the following built-in providers:

In order to use them, you have to add to your project the library of the provider, otherwise the build will fail.

Custom Provider

You can easily create your own providers, you can use this for reference:

class MixpanelProvider(private val context: Context, private val projectToken: String) : ProviderType {

    override var className = Class.forName("com.mixpanel.android.mpmetrics.MixpanelAPI")
    override var classInstance = className.getDeclaredMethod("getInstance", Context::class.java, String::class.java)
    override var classFunction = className.getDeclaredMethod("track", String::class.java, JSONObject::class.java)

    init {
        classInstance?.let {
            // get context
            try {
                it.invoke(className, context, projectToken)
            } catch (e: Exception) {
                Log.e("Raincoat", e.localizedMessage)
            }
        }
    }

    override fun log(eventName: String, parameters: HashMap<String, Any>?) {
        try {
            classFunction.invoke(classInstance, eventName, JSONObject(parameters))
        } catch (e: Exception) {
            Log.e("Raincoat", e.localizedMessage)
        }
    }
}

Installation

Add to your build.gradle:

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

then add the repository

compile 'com.github.matteocrippa:Raincoat:master-SNAPSHOT'

License

Raincoat is under MIT license. See the LICENSE file for more info.

raincoat's People

Contributors

matteocrippa avatar

Watchers

James Cloos avatar Sung Yu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.