Java Code Examples for com.google.android.gms.analytics.Tracker#send()

The following examples show how to use com.google.android.gms.analytics.Tracker#send() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsActivity.java    From android with MIT License 6 votes vote down vote up
public static void updateNotificationsPreference(FiveCallsApplication application,
                                                 AccountManager accountManager,
                                                 String result) {
    accountManager.setNotificationPreference(application, result);
    if (TextUtils.equals("0", result)) {
        OneSignalNotificationController.enableTopNotifications();
    } else if (TextUtils.equals("1", result)) {
        OneSignalNotificationController.enableAllNotifications();
    } else if (TextUtils.equals("2", result)) {
        OneSignalNotificationController.disableNotifications();
    }
    // If the user changes the settings there's no need to show the dialog in the future.
    accountManager.setNotificationDialogShown(application, true);
    // Log this to Analytics
    if (accountManager.allowAnalytics(application)) {
        Tracker tracker = application.getDefaultTracker();
        tracker.send(new HitBuilders.EventBuilder()
                .setCategory("Notifications")
                .setAction("NotificationSettingsChange")
                .setLabel(application.getApplicationContext().getResources()
                        .getStringArray(R.array.notification_options)[Integer.valueOf(result)])
                .setValue(1)
                .build());
    }
}
 
Example 2
Source File: GenresList.java    From moviedb-android with Apache License 2.0 6 votes vote down vote up
/**
 * Called to have the fragment instantiate its user interface view.
 *
 * @param inflater           sets the layout for the current view.
 * @param container          the container which holds the current view.
 * @param savedInstanceState If non-null, this fragment is being re-constructed from a previous saved state as given here.
 *                           Return the View for the fragment's UI, or null.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    rootView = inflater.inflate(R.layout.genreslist, container, false);
    activity = ((MainActivity) getActivity());
    spinner = (ProgressBar) rootView.findViewById(R.id.progressBar);
    listView = (AbsListView) rootView.findViewById(R.id.genresList);

    Tracker t = ((MovieDB) activity.getApplication()).getTracker();
    t.setScreenName("Genres");
    t.send(new HitBuilders.ScreenViewBuilder().build());

    return rootView;
}
 
Example 3
Source File: WidgetButtonService.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
private void sendSingleObservation() {
	if (mBound) {
	
		// Get tracker.
		Tracker t = ((PressureNetApplication) getApplication()).getTracker(
		    TrackerName.APP_TRACKER);
		// Build and send an Event.
		t.send(new HitBuilders.EventBuilder()
		    .setCategory(BarometerNetworkActivity.GA_CATEGORY_MAIN_APP)
		    .setAction(BarometerNetworkActivity.GA_ACTION_BUTTON)
		    .setLabel("small_widget_sending_single_observation")
		    .build());
		
		log("widget sending single observation");
		Message msg = Message.obtain(null, CbService.MSG_SEND_OBSERVATION, 0, 0);
		try {
			msg.replyTo = mMessenger;
			mService.send(msg);
		} catch (RemoteException e) {
			log("widget cannot send single obs, " + e.getMessage());
		}
	} else {
		log("widget failed to send single obs; data management error: not bound");
	}
}
 
Example 4
Source File: ConfigurationActivity.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setupActionBar(this);
    MainThreadBus.get().register(this);
    ChangeLogDialog.show(this, true);

    // TRACK: activity view.
    if (NoyzeApp.GOOGLE_ANALYTICS) {
        Tracker t = ((NoyzeApp) getApplication()).getTracker(
                NoyzeApp.TrackerName.APP_TRACKER);
        t.setScreenName(getClass().getSimpleName());
        t.send(new HitBuilders.AppViewBuilder().build());
    }
}
 
Example 5
Source File: NavigationActivity.java    From IdealMedia with Apache License 2.0 5 votes vote down vote up
private void setShuffleMode(boolean mode){
    PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("Shuffle", mode).commit();
    mBoundService.setShuffle(mode);
    if (playingFragment != null)
        playingFragment.shuffleItems();
    updatePlayPause();

    Tracker t = getTracker(NavigationActivity.TrackerName.APP_TRACKER);
    t.send(new HitBuilders.EventBuilder().setCategory("UX").setAction("shuffle").setLabel(String.valueOf(mode)).build());
}
 
Example 6
Source File: SettingsActivity.java    From android with MIT License 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    // We allow Analytics opt-out.
    if (accountManager.allowAnalytics(this)) {
        // Obtain the shared Tracker instance.
        FiveCallsApplication application = (FiveCallsApplication) getApplication();
        Tracker tracker = application.getDefaultTracker();
        tracker.setScreenName(TAG);
        tracker.send(new HitBuilders.ScreenViewBuilder().build());
    }
}
 
Example 7
Source File: PersonDetailFragment.java    From Movie-Check with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    Tracker defaultTracker = ((MovieCheckApplication) getActivity().getApplication()).getDefaultTracker();
    defaultTracker.setScreenName("Person Detail Screen");
    defaultTracker.send(new HitBuilders.ScreenViewBuilder().build());
}
 
Example 8
Source File: HelpActivity.java    From PressureNet with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onStart() {
	// Get tracker.
	Tracker t = ((PressureNetApplication) getApplication())
			.getTracker(TrackerName.APP_TRACKER);
	// Set screen name.
	t.setScreenName("Help");

	// Send a screen view.
	t.send(new HitBuilders.ScreenViewBuilder().build());
	super.onStart();
}
 
Example 9
Source File: NoyzeLibActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    ConfigurationActivity.setupActionBar(this);

    // TRACK: activity view.
    if (NoyzeApp.GOOGLE_ANALYTICS) {
        Tracker t = ((NoyzeApp) getApplication()).getTracker(
                NoyzeApp.TrackerName.APP_TRACKER);
        t.setScreenName(getClass().getSimpleName());
        t.send(new HitBuilders.AppViewBuilder().build());
    }
}
 
Example 10
Source File: MediaShortcutActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String action = intent.getAction();

    // We've got one mission and one mission only!
    if (!Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        finish();
        return;
    }

    // TRACK: activity view.
    if (NoyzeApp.GOOGLE_ANALYTICS) {
        Tracker t = ((NoyzeApp) getApplication()).getTracker(
                NoyzeApp.TrackerName.APP_TRACKER);
        t.setScreenName(getClass().getSimpleName());
        t.send(new HitBuilders.AppViewBuilder().build());
    }

    ConfigurationActivity.setupActionBar(this);
    setContentView(R.layout.media_shortcut);

    MEDIA_KEYCODES = getResources().getIntArray(R.array.media_control_keycodes);
    MEDIA_KEYNAMES = getResources().getStringArray(R.array.media_controls);
    assert(MEDIA_KEYCODES.length == MEDIA_KEYNAMES.length);

    ControlAdapter adapter = new ControlAdapter(getApplicationContext(),
            android.R.layout.simple_selectable_list_item, MEDIA_KEYNAMES);
    setListAdapter(adapter);
}
 
Example 11
Source File: TaskGetPlaylistVK.java    From IdealMedia with Apache License 2.0 5 votes vote down vote up
@Override
protected ArrayList<Track> doInBackground(String... params) {
    Activity activity = mActivity.get();
    if (null == activity) {
        return null;
    }

    method = params[0];
    long page = Long.valueOf(params[1]);
    if (params.length > 2) {
        if (TaskGetPlaylistVK.VK_METHOD_SEARCH.equals(method))
            query = params[2];
        if (TaskGetPlaylistVK.VK_METHOD_GET_POPULAR.equals(method))
            isForeignPopular = Boolean.parseBoolean(params[2]);
    }

    List<VKApiAudio> audios = new ArrayList<VKApiAudio>();

    if (VK_METHOD_GET.equals(method))
        audios = getAudio("audio.get", "", VK_PAGE_SIZE, VK_PAGE_SIZE * (page - 1));
    if (VK_METHOD_GET_POPULAR.equals(method))
        audios = getAudio("audio.getPopular", "", VK_PAGE_SIZE, VK_PAGE_SIZE * (page - 1));
    if (VK_METHOD_GET_RECOMMENDATIONS.equals(method))
        audios = getAudio("audio.getRecommendations", "", VK_PAGE_SIZE, VK_PAGE_SIZE * (page - 1));
    if (VK_METHOD_SEARCH.equals(method))
        audios = getAudio("audio.search", query, VK_PAGE_SIZE, VK_PAGE_SIZE * (page - 1));

    ArrayList<Track> tracks = new ArrayList<Track>();
    for (VKApiAudio audio : audios)
        tracks.add(Track.fromVKApiAudio(audio));

    Tracker t = ((NavigationActivity)activity).getTracker(NavigationActivity.TrackerName.APP_TRACKER);
    t.send(new HitBuilders.EventBuilder().setCategory("VK").setAction(method).build());

    return tracks;
}
 
Example 12
Source File: VKAudioFragment.java    From IdealMedia with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    adapter = new PlayerAdapter(activity, this, items);
    listView = (RecyclerView) view.findViewById(android.R.id.list);
    listView.setLayoutManager(new LinearLayoutManager(getActivity()));
    listView.setItemAnimator(new DefaultItemAnimator());
    listView.setAdapter(adapter);

    Tracker t = ((NavigationActivity)getActivity()).getTracker(NavigationActivity.TrackerName.APP_TRACKER);
    t.setScreenName("VK audio");
    t.send(new HitBuilders.AppViewBuilder().build());
}
 
Example 13
Source File: ActivityTracker.java    From ghwatch with Apache License 2.0 5 votes vote down vote up
/**
 * Track screen view.
 * 
 * @param context
 * @param appScreen
 */
public static void sendView(Context context, String appScreen) {
  if (!GHConstants.DEBUG) {
    Tracker t = getTracker(context);
    if (t != null) {
      t.setScreenName(appScreen);
      t.send(new HitBuilders.AppViewBuilder().build());
    }
  }
}
 
Example 14
Source File: MediaControlActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public void onHandleIntent(Intent intent) {
    if (null == intent) return;
    LOGD(TAG, "onHandleIntent(" + intent.toString() + ")");

    // TRACK: activity view.
    if (NoyzeApp.GOOGLE_ANALYTICS) {
        Tracker t = ((NoyzeApp) getApplication()).getTracker(
                NoyzeApp.TrackerName.APP_TRACKER);
        t.setScreenName(getClass().getSimpleName());
        t.send(new HitBuilders.AppViewBuilder().build());
    }

    Bundle extras = intent.getExtras();

    if (null == extras || !extras.containsKey(Intent.EXTRA_KEY_EVENT)) {
        Log.e(TAG, "KeyEvent null, cannot dispatch media event.");
        finish();
        return;
    }

    final int keyCode = extras.getInt(Intent.EXTRA_KEY_EVENT);
    if (!Utils.isMediaKeyCode(keyCode)) {
        Log.e(TAG, "KeyEvent was not one of KEYCODE_MEDIA_* events.");
        finish();
        return;
    }

    LOGD(TAG, "Dispatching media event: " + keyCode);
    AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE);
    AudioHelper helper = AudioHelper.getHelper(getApplicationContext(), manager);
    helper.dispatchMediaKeyEvent(getApplicationContext(), keyCode);

    finish();
}
 
Example 15
Source File: MediaShortcutActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String action = intent.getAction();

    // We've got one mission and one mission only!
    if (!Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        finish();
        return;
    }

    // TRACK: activity view.
    if (NoyzeApp.GOOGLE_ANALYTICS) {
        Tracker t = ((NoyzeApp) getApplication()).getTracker(
                NoyzeApp.TrackerName.APP_TRACKER);
        t.setScreenName(getClass().getSimpleName());
        t.send(new HitBuilders.AppViewBuilder().build());
    }

    ConfigurationActivity.setupActionBar(this);
    setContentView(R.layout.media_shortcut);

    MEDIA_KEYCODES = getResources().getIntArray(R.array.media_control_keycodes);
    MEDIA_KEYNAMES = getResources().getStringArray(R.array.media_controls);
    assert(MEDIA_KEYCODES.length == MEDIA_KEYNAMES.length);

    ControlAdapter adapter = new ControlAdapter(getApplicationContext(),
            android.R.layout.simple_selectable_list_item, MEDIA_KEYNAMES);
    setListAdapter(adapter);
}
 
Example 16
Source File: MiracastWidgetProvider.java    From miracast-widget with Apache License 2.0 4 votes vote down vote up
private void sendEventDisplayFound(Tracker tracker) {
    tracker.send(new HitBuilders.EventBuilder()
                   .setCategory("widget")
                   .setAction("display_added")
                   .build());
}
 
Example 17
Source File: GoogleAnalyticsManager.java    From pandroid with Apache License 2.0 4 votes vote down vote up
@Override
public void processParam(HashMap<String, Object> params) {

    for (Tracker tracker : mTrackers) {

        boolean session = params.containsKey(Param.NEW_SESSION);
        if (Event.Type.SCREEN.equals(params.get(Event.TYPE))) {
            tracker.setScreenName(params.get(Event.LABEL).toString());
            // Send a screen view.
            HitBuilders.ScreenViewBuilder screenViewBuilder = new HitBuilders.ScreenViewBuilder();
            screenViewBuilder = addMetrics(screenViewBuilder, params);
            screenViewBuilder = addDimensions(screenViewBuilder, params);
            if (session) {
                screenViewBuilder.setNewSession();
                session = false;
            }
            tracker.send(screenViewBuilder.build());
        }

        if (Event.Type.TIMER.equals(params.get(Event.TYPE))) {
            HitBuilders.TimingBuilder timingBuilder = new HitBuilders.TimingBuilder()
                    .setCategory(String.valueOf(params.get(Event.CATEGORY)))
                    .setValue(parseToLong(params.get(Event.DURATION)))
                    .setVariable(String.valueOf(params.get(Event.VARIABLE)))
                    .setLabel(String.valueOf(params.get(Event.LABEL)));
            timingBuilder = addMetrics(timingBuilder, params);
            timingBuilder = addDimensions(timingBuilder, params);
            if (session) {
                timingBuilder.setNewSession();
                session = false;
            }
            tracker.send(timingBuilder.build());
        }

        if (Event.Type.ACTION.equals(params.get(Event.TYPE))) {

            HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder()
                    .setCategory(String.valueOf(params.get(Event.CATEGORY)))
                    .setValue(parseToLong(params.get(Event.VALUE)))
                    .setAction(String.valueOf(params.get(Event.ACTION)))
                    .setLabel(String.valueOf(params.get(Event.LABEL)));
            eventBuilder = addMetrics(eventBuilder, params);
            eventBuilder = addDimensions(eventBuilder, params);
            if (session) {
                eventBuilder.setNewSession();
            }
            tracker.send(eventBuilder.build());
        }

    }


}
 
Example 18
Source File: CastDetails.java    From moviedb-android with Apache License 2.0 4 votes vote down vote up
/**
 * @param savedInstanceState if the fragment is being re-created from a previous saved state, this is the state.
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (save != null) {
        setTitle(save.getString("title"));
        currentId = save.getInt("currentId");
        timeOut = save.getInt("timeOut");
        if (timeOut == 0) {
            spinner.setVisibility(View.GONE);
            onOrientationChange(save);
        }
    }

    if (currentId != this.getArguments().getInt("id") || this.timeOut == 1) {
        currentId = this.getArguments().getInt("id");
        moreIcon.setVisibility(View.INVISIBLE);
        mSlidingTabLayout.setVisibility(View.INVISIBLE);
        mViewPager.setVisibility(View.INVISIBLE);
        spinner.setVisibility(View.VISIBLE);

        request = new JSONAsyncTask();
        new Thread(new Runnable() {
            public void run() {
                try {
                    request.execute(MovieDB.url + "person/" + currentId + "?append_to_response=combined_credits%2Cimages&api_key=" + MovieDB.key).get(10000, TimeUnit.MILLISECONDS);
                } catch (TimeoutException | ExecutionException | InterruptedException | CancellationException e) {
                    request.cancel(true);
                    // we abort the http request, else it will cause problems and slow connection later
                    if (conn != null)
                        conn.disconnect();
                    if (spinner != null)
                        activity.hideView(spinner);
                    if (getActivity() != null && !(e instanceof CancellationException)) {
                        getActivity().runOnUiThread(new Runnable() {
                            public void run() {
                                Toast.makeText(getActivity(), getResources().getString(R.string.timeout), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                    setTimeOut(1);
                }
            }
        }).start();
    }

    activity.setTitle(getTitle());
    activity.setCastDetailsFragment(this);

    new Handler().post(new Runnable() {
        @Override
        public void run() {
            castDetailsInfo = (CastDetailsInfo) castDetailsSlideAdapter.getRegisteredFragment(0);
            castDetailsCredits = (CastDetailsCredits) castDetailsSlideAdapter.getRegisteredFragment(1);
            castDetailsBiography = (CastDetailsBiography) castDetailsSlideAdapter.getRegisteredFragment(2);
        }
    });

    showInstantToolbar();

    iconMarginConstant = activity.getIconMarginConstant();
    iconMarginLandscape = activity.getIconMarginLandscape();
    iconConstantSpecialCase = activity.getIconConstantSpecialCase();
    twoIcons = activity.getTwoIcons();
    twoIconsToolbar = activity.getTwoIconsToolbar();
    oneIcon = activity.getOneIcon();
    oneIconToolbar = activity.getOneIconToolbar();

    Tracker t = ((MovieDB) activity.getApplication()).getTracker();
    t.setScreenName("CastDetails - " + getTitle());
    t.send(new HitBuilders.ScreenViewBuilder().build());
}
 
Example 19
Source File: MiracastWidgetProvider.java    From miracast-widget with Apache License 2.0 4 votes vote down vote up
private void sendEventDisplayFound(Tracker tracker) {
    tracker.send(new HitBuilders.EventBuilder()
                   .setCategory("widget")
                   .setAction("display_added")
                   .build());
}
 
Example 20
Source File: DocumentScannerApplication.java    From Document-Scanner with GNU General Public License v3.0 3 votes vote down vote up
/***
 * Tracking event
 *
 * @param category event category
 * @param action   action of the event
 * @param label    label
 */
public void trackEvent(String category, String action, String label) {
    Tracker t = getGoogleAnalyticsTracker();

    // Build and send an Event.
    t.send(new HitBuilders.EventBuilder().setCategory(category).setAction(action).setLabel(label).build());
}