コード例 #1
0
      @Override
      public void run() {

        final MPDbAdapter dbMock =
            new MPDbAdapter(getContext()) {
              @Override
              public int addJSON(JSONObject message, MPDbAdapter.Table table) {
                mMessages.add(message);
                return 1;
              }
            };

        final AnalyticsMessages analyticsMessages =
            new AnalyticsMessages(getContext()) {
              @Override
              public MPDbAdapter makeDbAdapter(Context context) {
                return dbMock;
              }
            };

        MixpanelAPI mixpanel =
            new TestUtils.CleanMixpanelAPI(getContext(), mMockPreferences, "TEST TOKEN") {
              @Override
              protected AnalyticsMessages getAnalyticsMessages() {
                return analyticsMessages;
              }
            };
        mixpanel.clearPreferences();
        mixpanel.track("test in thread", new JSONObject());
      }
コード例 #2
0
 public MessagesAdapter(
     Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
   super(context, layout, c, from, to, flags);
   this.context = context;
   mayday = new Mayday(context);
   mixpanel = MixpanelAPI.getInstance(context, Constants.MIXPANEL_TOKEN);
   preferences = context.getSharedPreferences("boutlineData", Context.MODE_PRIVATE);
   String userId = preferences.getString("boutlineUserId", "");
   mixpanel.identify(userId);
 }
コード例 #3
0
  public void testGeneratedDistinctId() {
    String fakeToken = UUID.randomUUID().toString();
    MixpanelAPI mixpanel =
        new TestUtils.CleanMixpanelAPI(getContext(), mMockPreferences, fakeToken);
    String generatedId1 = mixpanel.getDistinctId();
    assertTrue(generatedId1 != null);

    mixpanel.clearPreferences();
    String generatedId2 = mixpanel.getDistinctId();
    assertTrue(generatedId2 != null);
    assertTrue(generatedId1 != generatedId2);
  }
コード例 #4
0
  public void testTrackCharge() {
    final List<JSONObject> messages = new ArrayList<JSONObject>();
    final AnalyticsMessages listener =
        new AnalyticsMessages(getContext()) {
          @Override
          public void eventsMessage(EventDescription heard) {
            throw new RuntimeException("Should not be called during this test");
          }

          @Override
          public void peopleMessage(JSONObject heard) {
            messages.add(heard);
          }
        };

    class ListeningAPI extends TestUtils.CleanMixpanelAPI {
      public ListeningAPI(Context c, Future<SharedPreferences> referrerPrefs, String token) {
        super(c, referrerPrefs, token);
      }

      @Override
      protected AnalyticsMessages getAnalyticsMessages() {
        return listener;
      }
    }

    MixpanelAPI api = new ListeningAPI(getContext(), mMockPreferences, "TRACKCHARGE TEST TOKEN");
    api.getPeople().identify("TRACKCHARGE PERSON");

    JSONObject props;
    try {
      props = new JSONObject("{'$time':'Should override', 'Orange':'Banana'}");
    } catch (JSONException e) {
      throw new RuntimeException("Can't construct fixture for trackCharge test");
    }

    api.getPeople().trackCharge(2.13, props);
    assertEquals(messages.size(), 1);

    JSONObject message = messages.get(0);

    try {
      JSONObject append = message.getJSONObject("$append");
      JSONObject newTransaction = append.getJSONObject("$transactions");
      assertEquals(newTransaction.optString("Orange"), "Banana");
      assertEquals(newTransaction.optString("$time"), "Should override");
      assertEquals(newTransaction.optDouble("$amount"), 2.13);
    } catch (JSONException e) {
      fail("Transaction message had unexpected layout:\n" + message.toString());
    }
  }
コード例 #5
0
  public void testLooperDestruction() {

    final BlockingQueue<JSONObject> messages = new LinkedBlockingQueue<JSONObject>();

    // If something terrible happens in the worker thread, we
    // should make sure
    final MPDbAdapter explodingDb =
        new MPDbAdapter(getContext()) {
          @Override
          public int addJSON(JSONObject message, MPDbAdapter.Table table) {
            messages.add(message);
            throw new RuntimeException("BANG!");
          }
        };
    final AnalyticsMessages explodingMessages =
        new AnalyticsMessages(getContext()) {
          // This will throw inside of our worker thread.
          @Override
          public MPDbAdapter makeDbAdapter(Context context) {
            return explodingDb;
          }
        };
    MixpanelAPI mixpanel =
        new TestUtils.CleanMixpanelAPI(
            getContext(), mMockPreferences, "TEST TOKEN testLooperDisaster") {
          @Override
          protected AnalyticsMessages getAnalyticsMessages() {
            return explodingMessages;
          }
        };

    try {
      mixpanel.clearPreferences();
      assertFalse(explodingMessages.isDead());

      mixpanel.track("event1", null);
      JSONObject found = messages.poll(1, TimeUnit.SECONDS);
      assertNotNull(found);
      Thread.sleep(1000);
      assertTrue(explodingMessages.isDead());

      mixpanel.track("event2", null);
      JSONObject shouldntFind = messages.poll(1, TimeUnit.SECONDS);
      assertNull(shouldntFind);
      assertTrue(explodingMessages.isDead());
    } catch (InterruptedException e) {
      fail("Unexpected interruption");
    }
  }
コード例 #6
0
    @Override
    public void initPushHandling(String senderID) {
      if (MPConfig.DEBUG) Log.d(LOGTAG, "initPushHandling");

      if (!ConfigurationChecker.checkPushConfiguration(mContext)) {
        Log.i(LOGTAG, "Can't start push notification service. Push notifications will not work.");
        Log.i(LOGTAG, "See log tagged " + ConfigurationChecker.LOGTAG + " above for details.");
      } else { // Configuration is good for push notifications
        final String pushId = getPushId();
        if (pushId == null) {
          if (MPConfig.DEBUG) Log.d(LOGTAG, "Registering a new push id");

          try {
            Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
            registrationIntent.putExtra(
                "app", PendingIntent.getBroadcast(mContext, 0, new Intent(), 0)); // boilerplate
            registrationIntent.putExtra("sender", senderID);
            mContext.startService(registrationIntent);
          } catch (SecurityException e) {
            Log.w(LOGTAG, e);
          }
        } else {
          MixpanelAPI.allInstances(
              new InstanceProcessor() {
                @Override
                public void process(MixpanelAPI api) {
                  if (MPConfig.DEBUG) Log.d(LOGTAG, "Using existing pushId " + pushId);
                  api.getPeople().setPushRegistrationId(pushId);
                }
              });
        }
      } // endelse
    }
コード例 #7
0
  @Override
  public void onConnected(Bundle bundle) {
    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
      Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
      String personName = currentPerson.getDisplayName();
      String personPhoto = currentPerson.getImage().getUrl();
      String firstName = currentPerson.getName().getGivenName();
      String lastName = currentPerson.getName().getFamilyName();
      String personGooglePlusProfile = currentPerson.getUrl();
      String date = currentPerson.getBirthday();
      if (date == null) {
        date = "";
      }
      int gender = currentPerson.getGender();
      String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

      Intent mIntent = new Intent(getActivity(), LoginUserDetails.class);
      mIntent.putExtra("login_method", "google");
      mIntent.putExtra("email", email);
      mIntent.putExtra("first_name", firstName);
      mIntent.putExtra("gender", gender);
      mIntent.putExtra("last_name", lastName);
      mIntent.putExtra("photo", personPhoto);

      mixpanel.track("Login - Google");
      startActivity(mIntent);
    } else {
      Toast.makeText(getContext(), "You do not have a google+ account", Toast.LENGTH_SHORT).show();
      showSocialLoginDialog();
    }

    Log.d(TAG, "onConnected:" + bundle);
    mShouldResolve = false;
  }
コード例 #8
0
  private void parseFBData(JSONObject jsonObject, AccessToken token) {
    try {
      String id = jsonObject.getString("id");
      String email = jsonObject.getString("email");
      //                            String name = jsonObject.getString("name");
      String gender = jsonObject.getString("gender");
      String first_name = jsonObject.getString("first_name");
      String last_name = jsonObject.getString("last_name");

      Intent mIntent = new Intent(getActivity(), LoginUserDetails.class);
      mIntent.putExtra("login_method", "facebook");
      mIntent.putExtra("email", email);
      mIntent.putExtra("first_name", first_name);
      mIntent.putExtra("last_name", last_name);
      //            mIntent.putExtra("id", id);
      mIntent.putExtra("id", token.getUserId());
      //                            mIntent.putExtra("name",name);
      if (jsonObject.has("birthday")) {
        String birthday = jsonObject.getString("birthday");
        mIntent.putExtra("birthday", birthday);
      }

      mixpanel.track("Login - Facebook");
      mIntent.putExtra("gender", gender);
      startActivity(mIntent);
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
コード例 #9
0
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mixpanel = MixpanelAPI.getInstance(getActivity(), mixPanelProjectToken);

    smsPB = (ProgressView) view.findViewById(R.id.sms_pb_progressview);
    signInBtn = (ImageButton) view.findViewById(R.id.signInSMSButton);
    sms_edittext = (EditText) view.findViewById(R.id.signInSMCode);

    AppUser appUserInstance = AppUser.getInstance();
    smsURL =
        appUserInstance.getBaseUrl()
            + "KLR9zwarL1iGs8EFyZLs4keh/com.solidPeak.smartcom.requests.application.getUserKeyCheck.htm?";

    signInBtn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            verifySMS(sms_edittext.getText().toString());
          }
        });

    mGoogleApiClient =
        new GoogleApiClient.Builder(getActivity())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(new Scope(Scopes.PROFILE))
            .build();

    sharedPreferences = getActivity().getSharedPreferences("SmartCommunity", Activity.MODE_PRIVATE);
  }
コード例 #10
0
ファイル: RouteFragment.java プロジェクト: haovn577/open
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   mixpanelAPI.track(ROUTING_START, null);
   createGroup();
   bus.register(this);
 }
コード例 #11
0
  public void testIdentifyAfterSet() {
    final List<JSONObject> messages = new ArrayList<JSONObject>();

    final AnalyticsMessages listener =
        new AnalyticsMessages(getContext()) {
          @Override
          public void peopleMessage(JSONObject heard) {
            messages.add(heard);
          }
        };

    MixpanelAPI mixpanel =
        new TestUtils.CleanMixpanelAPI(
            getContext(), mMockPreferences, "TEST TOKEN testIdentifyAfterSet") {
          @Override
          protected AnalyticsMessages getAnalyticsMessages() {
            return listener;
          }
        };

    MixpanelAPI.People people = mixpanel.getPeople();
    people.increment("the prop", 0L);
    people.append("the prop", 1);
    people.set("the prop", 2);
    people.increment("the prop", 3L);
    people.increment("the prop", 4);
    people.append("the prop", 5);
    people.append("the prop", 6);
    people.identify("Personal Identity");

    assertEquals(messages.size(), 7);
    try {
      for (JSONObject message : messages) {
        String distinctId = message.getString("$distinct_id");
        assertEquals(distinctId, "Personal Identity");
      }

      assertTrue(messages.get(0).has("$add"));
      assertTrue(messages.get(1).has("$append"));
      assertTrue(messages.get(2).has("$set"));
      assertTrue(messages.get(3).has("$add"));
      assertTrue(messages.get(4).has("$add"));
    } catch (JSONException e) {
      fail("Unexpected JSON error in stored messages.");
    }
  }
コード例 #12
0
  public void testAlias() {
    final ServerMessage mockPoster =
        new ServerMessage() {
          @Override
          public byte[] performRequest(String endpointUrl, List<NameValuePair> nameValuePairs) {
            try {
              assertEquals(nameValuePairs.get(0).getName(), "data");
              final String jsonData = Base64Coder.decodeString(nameValuePairs.get(0).getValue());
              JSONArray msg = new JSONArray(jsonData);
              JSONObject event = msg.getJSONObject(0);
              JSONObject properties = event.getJSONObject("properties");

              assertEquals(event.getString("event"), "$create_alias");
              assertEquals(properties.getString("distinct_id"), "old id");
              assertEquals(properties.getString("alias"), "new id");
            } catch (JSONException e) {
              throw new RuntimeException("Malformed data passed to test mock", e);
            }
            return TestUtils.bytes("1\n");
          }
        };

    final AnalyticsMessages listener =
        new AnalyticsMessages(getContext()) {
          @Override
          protected ServerMessage getPoster() {
            return mockPoster;
          }
        };

    MixpanelAPI metrics =
        new TestUtils.CleanMixpanelAPI(getContext(), mMockPreferences, "Test Message Queuing") {
          @Override
          protected AnalyticsMessages getAnalyticsMessages() {
            return listener;
          }
        };

    // Check that we post the alias immediately
    metrics.identify("old id");
    metrics.alias("new id", "old id");
  }
コード例 #13
0
  @Override
  public void onActivityStopped(Activity activity) {
    // Remove from the current list of running activities
    status.remove(activity.toString());

    // If there are no running activities, the app is backgrounded
    // In this scenario, log the event to Mixpanel
    if (status.isEmpty()) {
      // Send the session tracking information to Mixpanel
      mixpanelCallbacks.track("$app_open");

      // Mark the current session as inactive so we properly start a new one
      mixpanelCallbacks.unregisterSuperProperty("Session");

      // Force all queued Mixpanel data to be sent to Mixpanel
      mixpanelCallbacks.flush();
    }

    Log.d("Current Activities", "onStop() " + status.toString());
  }
コード例 #14
0
  public void trackEvent(String eventName) {
    JSONObject props = new JSONObject();

    try {
      props.put("Email", InfoUtil.getEmailAddress(context));
      props.put("Date", new Date().toString());
      mixpanelAPI.track(eventName, props);
    } catch (JSONException e) {
      // e.printStackTrace();
    }
  }
コード例 #15
0
  @Override
  public void onActivityStarted(Activity activity) {
    // Add to the current list of running activities
    status.add(activity.toString());

    // Check to see if there is a current session in progress or not
    // If there is no active session, start a new timer and log to Mixpanel
    if (!mixpanelCallbacks.getSuperProperties().has("Session")) {
      // Start session timer for tracking app session lengths
      mixpanelCallbacks.timeEvent("$app_open");

      // Register a super property to indicate the session is in progress
      JSONObject superprops = new JSONObject();
      try {
        superprops.put("Session", true);
      } catch (JSONException e) {
        Log.e("Send", "Unable to add super properties to JSONObject", e);
      }
      mixpanelCallbacks.registerSuperProperties(superprops);
    }

    Log.d("Current Activities", "onStart() " + status.toString());
  }
コード例 #16
0
 private void handleRegistrationIntent(Intent intent) {
   final String registration = intent.getStringExtra("registration_id");
   if (intent.getStringExtra("error") != null) {
     Log.e(LOGTAG, "Error when registering for GCM: " + intent.getStringExtra("error"));
   } else if (registration != null) {
     if (MPConfig.DEBUG) Log.d(LOGTAG, "Registering GCM ID: " + registration);
     MixpanelAPI.allInstances(
         new InstanceProcessor() {
           @Override
           public void process(MixpanelAPI api) {
             api.getPeople().setPushRegistrationId(registration);
           }
         });
   } else if (intent.getStringExtra("unregistered") != null) {
     if (MPConfig.DEBUG) Log.d(LOGTAG, "Unregistering from GCM");
     MixpanelAPI.allInstances(
         new InstanceProcessor() {
           @Override
           public void process(MixpanelAPI api) {
             api.getPeople().clearPushRegistrationId();
           }
         });
   }
 }
コード例 #17
0
  public void testIdentifyAndGetDistinctId() {
    MixpanelAPI metrics =
        new TestUtils.CleanMixpanelAPI(getContext(), mMockPreferences, "Identify Test Token");

    String generatedId = metrics.getDistinctId();
    assertNotNull(generatedId);

    String emptyId = metrics.getPeople().getDistinctId();
    assertNull(emptyId);

    metrics.identify("Events Id");
    String setId = metrics.getDistinctId();
    assertEquals("Events Id", setId);

    String stillEmpty = metrics.getPeople().getDistinctId();
    assertNull(stillEmpty);

    metrics.getPeople().identify("People Id");
    String unchangedId = metrics.getDistinctId();
    assertEquals("Events Id", unchangedId);

    String setPeopleId = metrics.getPeople().getDistinctId();
    assertEquals("People Id", setPeopleId);
  }
コード例 #18
0
  public static void createUser(android.content.Context context, Pessoa pessoa) {

    MixpanelAPI mixpanel = MixpanelAPI.getInstance(context, MIXPANEL_TOKEN);

    mixpanel.getPeople().identify(pessoa.getUid());
    mixpanel.getPeople().initPushHandling(CommonUtilities.SENDER_ID);

    mixpanel.getPeople().set("Nome", pessoa.getNome());
    mixpanel.getPeople().set("Cidade", pessoa.getCidade());
    mixpanel.getPeople().set("Pais", pessoa.getPais());
    mixpanel.getPeople().set("Sexo", pessoa.getSexo());
    mixpanel.getPeople().set("Aniversario", pessoa.getAniversario());
    mixpanel.getPeople().set("Status de relacionamento", pessoa.getRelationship_status());
  }
コード例 #19
0
 protected void onCreate(Bundle paramBundle)
 {
   TraceMachine.startTracing("SurveyActivity");
   try
   {
     TraceMachine.enterMethod(this._nr_trace, "SurveyActivity#onCreate", null);
     super.onCreate(paramBundle);
     this.mIntentId = getIntent().getIntExtra("com.mixpanel.android.surveys.SurveyActivity.INTENT_ID_KEY", Integer.MAX_VALUE);
     this.mUpdateDisplayState = UpdateDisplayState.claimDisplayState(this.mIntentId);
     if (this.mUpdateDisplayState == null)
     {
       Log.e("MixpanelAPI.SrvyActvty", "SurveyActivity intent received, but nothing was found to show.");
       finish();
       TraceMachine.exitMethod();
       return;
     }
   }
   catch (NoSuchFieldError localNoSuchFieldError)
   {
     for (;;)
     {
       TraceMachine.enterMethod(null, "SurveyActivity#onCreate", null);
     }
     this.mMixpanel = MixpanelAPI.getInstance(this, this.mUpdateDisplayState.getToken());
     if (!isShowingInApp()) {
       break label116;
     }
   }
   onCreateInAppNotification(paramBundle);
   for (;;)
   {
     TraceMachine.exitMethod();
     return;
     label116:
     if (isShowingSurvey()) {
       onCreateSurvey(paramBundle);
     } else {
       finish();
     }
   }
 }
コード例 #20
0
 /**
  * Tracks a Mixpanel event with properties. (for compatibilty with iOS version)
  *
  * @param event
  * @param properties
  */
 @ReactMethod
 public void trackWithProperties(String event, ReadableMap properties) {
   mixpanel.track(event, this.readableMapToJson(properties));
 }
コード例 #21
0
 private MixPanelUtil(Context context) {
   this.context = context;
   mixpanelAPI = MixpanelAPI.getInstance(context, PROJECT_TOKEN);
 }
コード例 #22
0
  public static void sendEvent(android.content.Context context, String eventTitle) {

    MixpanelAPI mixpanel = MixpanelAPI.getInstance(context, MIXPANEL_TOKEN);

    mixpanel.track(eventTitle, null);
  }
コード例 #23
0
 @ReactMethod
 public void set(ReadableMap properties) {
   mixpanel.getPeople().set(this.readableMapToJson(properties));
 }
コード例 #24
0
 /**
  * Tracks a charge for the identified user.
  *
  * @param charge
  */
 @ReactMethod
 public void peopleTrackCharge(double charge) {
   mixpanel.getPeople().trackCharge(charge, null);
 }
コード例 #25
0
 /**
  * Increments properties for the identified user.
  *
  * @param properties
  */
 @ReactMethod
 public void peopleIncrement(ReadableMap properties) {
   mixpanel.getPeople().increment(this.readableMapToNumberMap(properties));
 }
コード例 #26
0
 /**
  * Tracks a charge (with properties) for the identified user.
  *
  * @param charge
  * @param properties
  */
 @ReactMethod
 public void peopleTrackChargeWithProperties(double charge, ReadableMap properties) {
   mixpanel.getPeople().trackCharge(charge, this.readableMapToJson(properties));
 }
コード例 #27
0
ファイル: AppModule.java プロジェクト: haovn577/open
 @Provides
 @Singleton
 MixpanelAPI provideMixpanelApi() {
   return MixpanelAPI.getInstance(context, context.getString(R.string.mixpanel_token));
 }
コード例 #28
0
 /**
  * Get shared instance.
  *
  * @param apiToken
  */
 @ReactMethod
 public void sharedInstanceWithToken(String apiToken) {
   this.mixpanel = MixpanelAPI.getInstance(this.reactContext, apiToken);
 }
コード例 #29
0
 /**
  * Starts timing a Mixpanel event. PPTMixpanelManager.track() must be called once the event you're
  * timing is complete.
  *
  * @param event
  */
 @ReactMethod
 public void timeEvent(String event) {
   mixpanel.timeEvent(event);
 }
コード例 #30
0
 /**
  * Tracks a Mixpanel event.
  *
  * @param event
  * @param properties
  */
 @ReactMethod
 public void track(String event) {
   mixpanel.track(event);
 }