Google Event Tracker v3

2019-05-14 18:03发布

I've a problem with the google Event Tracker. Following the official documentation Google develop Documentation i add the xml file with my id. After on the activity i create a new Tracker, and try to push a new event, but the method "sendevent" does not exist.

this is my code

The import:

import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;

//I think i've to only import the tracker

and the simple code

 Long opt_value;
          Tracker MyTracker;
           MyTracker.sendEvent("ui_action", "button_press", "play_button", opt_value);

And the error:

The method sendEvent(String, String, String, Long) is undefined for the type Tracker

Thank's to all and sorry for my bad english

Edit: Now i'm tryng with

  MyTracker.send(MapBuilder
      .createEvent("evt",    
                   "Id",    
                   ""+idSong,       
                   null).build()
  );  

but on logcat i have: 08-20 10:45:35.320: I/GAV3(5371): Thread[GAThread,5,main]: No campaign data found.

1条回答
Juvenile、少年°
2楼-- · 2019-05-14 18:56

To use sendEvent method you should first initialize the tracker like:

private static Tracker m_GaTracker;
private GoogleAnalytics m_GaInstance;
m_GaInstance = GoogleAnalytics.getInstance(context);
m_GaTracker = m_GaInstance.getTracker("UA---");
m_GaInstance.setDefaultTracker(m_GaTracker);
m_GaTracker.sendEvent("your value ", " ", " ", 0L);

The above code works with V2 lib , to work with V3 use:

  // Instead, send a single hit with session control to start the new session.
    mTracker.send(MapBuilder
      .createEvent("UX", "appstart", null, null)
      .set(Fields.SESSION_CONTROL, "start")
      .build()
    );
查看更多
登录 后发表回答