Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.mbiamont:ga-annotations-plugin

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.mbiamont:ga-annotations-plugin

Gradle plugin to use Google Analytics Annotations Library

  • 1.1.1
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

#Google Analytics Annotations

Android library to use Google Analytics through annotations.

Android Arsenal

Maven central Maven central

Installation

In your build.gradle file add these lines :

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.github.mbiamont:ga-annotations-plugin:1.1.1'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'GAAnnotations'

(...)

dependencies {
    (...)
    compile 'com.github.mbiamont:ga-annotations-library:1.2.1'
}

Usage

Initialization

In the onCreate() method of your Application class, add this line :

  AnalyticsManager.getInstance().init(context, "YOUR_GOOGLE_ANALYTICS_TRACKER_ID");

Track event

@TrackEvent(category = "ui_action", action = "on_click", label = "on_click_login_button", value = 1)
private void onLoginButtonClicked(){
  (...)
}

Track screen

@TrackScreen(name = "MainActivity")
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  (...)
}

More

Use multiple TrackerId

If you have to use multiple trackerId in your application, you can define for each event or screen the tracker to use.

Example :

@TrackScreen(trackerId= "UA-XXXX1", name = "MainActivity")
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  (...)
}

DebugMode

If you just want to check if the tracks are correctly implemented; you can use the debugMode. It'll print tracks in LogCat instead of send them.

Just replace AnalyticsManager.getInstance().init() by

AnalyticsManager.getInstance().debugMode(context, true);

Manual track

Sometimes, you cannot use annotations (if your tracks require a condition for example). In this case, you can use trackers manually :

private void onLoginButtonClicked(){
  if(user.isLogged()){
    AnalyticsManager.getInstance().trackEvent(new Event.Builder()
            .withCategory("ui_action")
            .withAction("on_click")
            .withLabel("on_click_login_button")
            .build());
    //or simply : AnalyticsManager.getInstance().trackEvent("ui_action", "on_click", "on_click_login_button", 1);
  }
  (...)
}

or

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  if(user.isLogged()){
    AnalyticsManager.getInstance().trackScreen("MainActivity");
  }
  (...)
}

License

Copyright 2015-2016 Melvin Biamont

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

FAQs

Package last updated on 25 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc