0

I am trying to set context for easytracker before using it in my on create method as :

 Context context= this; 
 EasyTracker.getInstance().setContext(context);

But getInstance is needing a context and when I call setContext, it becomes red-underlined saying "The method setContext(Context, ParameterLoader, ServiceManager) in the type EasyTracker is not applicable for the arguments (Context)".

I want to set context for easytracker to track my button clicks.

halfer
  • 19,824
  • 17
  • 99
  • 186
user3559063
  • 37
  • 2
  • 10

2 Answers2

0

Basically, what the error is saying is that if you call getInstance() you need to provide it a Context object. You're doing this within an Activity, so getInstance(this) should work for you (in this case, this will be matching your current Context). So Change this

EasyTracker.getInstance().setContext(context);

to

EasyTracker.getInstance(context).setContext(context);

Or to set easytracker instance,try this

EasyTracker easyTracker = EasyTracker.getInstance(context);

and track button click event as

easyTracker.send(MapBuilder
          .createEvent("ui_action",     // Event category (required)
                       "button_press",  // Event action (required)
                       "play_button",   // Event label
                       null)            // Event value
          .build()
      );
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
0

There is no need to use setContext here, just follow Google's tutorial:

@Override
  public void onStart() {
    super.onStart();
    ... // The rest of your onStart() code.
    EasyTracker.getInstance(this).activityStart(this);  // Add this method.
  }

  @Override
  public void onStop() {
    super.onStop();
    ... // The rest of your onStop() code.
    EasyTracker.getInstance(this).activityStop(this);  // Add this method.
  }
Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85
  • My my onClick is in oncreate method, not in onstart or onstop – user3559063 May 31 '14 at 11:42
  • The EasyTracker is used to see when the screens are displayed, for events you need to create custom trackers: https://developers.google.com/analytics/devguides/collection/android/v4/events – Yoann Hercouet May 31 '14 at 11:49