Android Open Source - com.elsewhat.android.slideshow Analytics






From Project

Back to project page com.elsewhat.android.slideshow.

License

The source code is released under:

Copyright (C) 2012 Dagfinn Parnas <dagfinn.parnas@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Sof...

If you think the Android project com.elsewhat.android.slideshow listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.elsewhat.android.slideshow.api;
// w ww  .  j  a  v a  2s.  c  o  m
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.elsewhat.android.slideshow.activities.SlideshowPreferences;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;

public class Analytics {
  //TODO-FORK: Add your own google analytics id
  public final static String ANALYTICS_ID = "UA-28244457-1";
  private static GoogleAnalyticsTracker tracker = GoogleAnalyticsTracker
      .getInstance();
  private static boolean isStarted = false;

  public static void trackPageView(Context context, String pageName) {
    if (isEnabled(context)) {
      try {
        if (!isStarted) {

          tracker.startNewSession(Analytics.ANALYTICS_ID, 15, context);
          isStarted = true;

        }
        tracker.trackPageView(pageName);
      } catch (RuntimeException e) {
        Log.d("RedditTV", "Hmmm exception during analytics", e);
      }
    }
  }

  public static void trackEvent(Context context, String category,
      String name, String value) {
    if (isEnabled(context)) {
      try {
        if (!isStarted) {

          tracker.startNewSession(Analytics.ANALYTICS_ID, 15, context);
          isStarted = true;

        }
        // analytics don't like whitespace
        name = name.replaceAll(" ", "");
        if (value == null) {
          value = "null";
        }
        value = value.replaceAll(" ", "");
        tracker.trackEvent(category, name, value, 0);
      } catch (RuntimeException e) {
        Log.d("RedditTV", "Hmmm exception during analytics", e);
      }
    }

  }

  public static boolean isEnabled(Context context) {
    SharedPreferences settings = context.getSharedPreferences(
        SlideshowPreferences.PREFS_NAME, 0);
    return settings.getBoolean(SlideshowPreferences.KEY_DO_ANALYTICS, false);
  }
}




Java Source Code List

com.elsewhat.android.slideshow.activities.ChromecastAddin.java
com.elsewhat.android.slideshow.activities.ISlideshowInstance.java
com.elsewhat.android.slideshow.activities.SlideshowActivity.java
com.elsewhat.android.slideshow.activities.SlideshowDreamService.java
com.elsewhat.android.slideshow.activities.SlideshowPreferences.java
com.elsewhat.android.slideshow.api.Analytics.java
com.elsewhat.android.slideshow.api.AndroidUtils.java
com.elsewhat.android.slideshow.api.AsyncQueueableObject.java
com.elsewhat.android.slideshow.api.AsyncReadQueue.java
com.elsewhat.android.slideshow.api.CustomGallery.java
com.elsewhat.android.slideshow.api.DeletablePreference.java
com.elsewhat.android.slideshow.api.DownloadableObject.java
com.elsewhat.android.slideshow.api.FileDownloader.java
com.elsewhat.android.slideshow.api.FileUtils.java
com.elsewhat.android.slideshow.api.FlingKeyEvent.java
com.elsewhat.android.slideshow.api.ImageAdapter.java
com.elsewhat.android.slideshow.api.QueueablePhotoObject.java
com.elsewhat.android.slideshow.api.ReadOnlyPreference.java
com.elsewhat.android.slideshow.api.SlideshowBackend.java
com.elsewhat.android.slideshow.api.SlideshowPhotoCached.java
com.elsewhat.android.slideshow.api.SlideshowPhotoDrawable.java
com.elsewhat.android.slideshow.api.SlideshowPhoto.java
com.elsewhat.android.slideshow.backend.FlickrPublicSetBackend.java
com.elsewhat.android.slideshow.backend.OPMLBackend.java
com.elsewhat.android.slideshow.backend.SmugMugRecentBackend.java