Git Product home page Git Product logo

8digits-android-sdk's Introduction

8digits.com Android SDK

Usage

Adding SDK To Your Project

You can add 8digits Android SDK to your project by adding 8digits-sdk.jar file to your project.

Getting client instance

You should create new instance of client in your main activity.

this.eightdigitsClient = EightDigitsClient.createInstance(this, "<API_URL>", "<TRACKING_CODE>");

8Digits client is a singleton class, if you want to get instance of class in other activities, you should type code below in your activity's onCreate event.

this.eightdigitsClient = EightDigitsClient.getInstance();

Creating Auth token (Creating session)

After getting instance of client, you should create authToken to make requests. To create authToken

this.eightdigitsClient.auth("<API_KEY>");

Creating authToken in your main activity is enough. You don't have to call this method in other activities.

Creating New Visit

After creating your session (Creating auth token), you should call newVisit method which creates sessionCode and hitCode. 8digits SDK will associate hitCode and sessionCode with your view to use later when sending events.

this.eightdigitsClient.newVisit("<Title of Visit>", "<Path>");

Setting Location Of Visit

Before calling newVisit method, you should call setLocation("<Latitude>", "<Longtitude>") method to set location of visitor.

Creating New Hit

If you want to create new hitCode you can call newScreen method of client.

int hitCode = this.eightdigitsClient.newScreen("<Screen Name>", "<Screen Path>");

Re-creating Hit

Every time user navigate to your activity, you need create new hitCode. Doing this is so easy in 8digits SDK. You just need to call onRestart method of client in your Activity's onRestart method. You can see example usage below.

@Override
    protected void onRestart() {
      super.onRestart();
      this.eightdigitsClient.onRestart("<Title of Visit>", "<Path>");
}

Creating New Event

To create a new event, you can use newEvent method. 8digits SDK automatically adds hitCode to your new event request. SDK, sends events to the server asynchronously and does not affect your application's user experience.

this.eightdigitsClient.newEvent("<Event Key>", "<Event Value>");

Getting User Score

You can get user badges with score method. This method just takes one callback argument. Callback is a instance of EightDigitsResultListener class. You can see example below.

this.eightdigitsClient.score(new EightDigitsResultListener() {
        
        @Override
        public void handleResult(JSONObject result) {
          // TODO Auto-generated method stub
          
        }
      });

You need to control error key in handleResult method. If result has error key, this means your api request is failed.

Getting User Badges

You can get user badges with visitorBadges method. This method just takes one callback argument. Callback is a instance of EightDigitsResultListener class. You can call this method how you call score method. You can see example above.

Getting Account Badges

You can get account badges with badges method. This method just takes one callback argument. Callback is a instance of EightDigitsResultListener class. You can call this method how you call score method. You can see example above.

Displaying Badge Image in ImageView

To display an image of badge in an ImageView, you should use badgeImage method. First parameter is your image view from your view, second argument is badge's id.

Ending Hit

You should end user hits in your activities onDestroy method. You can do this by calling, endScreen method. You don't need to send any parameter to this method.

this.eightdigitsClient.endScreen();

Ending Visit

You should end user visit. You should call this method only in your main activity's onDestroy method.

this.eightdigitsClient.endVisit();

Setting Visitor Attribute And Avatar

To set attribute of visitor, you should use setVisitorAttribute method, to set avatar of visitor you should use setVisitorAvatar method.

this.eightdigitsClient.setVisitorAttribute("fullName", "Foo Bar");
this.eightdigitsClient.setVisitorAvatar("http://foo.com/images/bar.jpg");

Setting Visitor GSM

You can set visitor GSM by calling identifyAndSetVisitorGSM method after creating visit.

this.eightdigitsClient.identifyAndSetVisitorGSM();

Configuring Logging

If you want to disable logging for EightDigitsClient class you can call setLoggingEnabled method. To disable logging, after creating an instance of EightDigitsClient class, you should call method as shown below.

this.eightdigitsClient.setLoggingEnabled(false);

Default value of logging is true which means every http request to 8digits API servers will be logged to LogCat. We suggest disabling logging when you release your application to market because of security reasons.

Author

Gurkan Oluc (@grkn) [email protected]

8digits-android-sdk's People

Contributors

gurkanoluc avatar

Watchers

 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.