Skip to content

Instantly share code, notes, and snippets.

@fmedlin
Last active November 1, 2021 12:59
Show Gist options
  • Save fmedlin/69b442c90db4e928cf105b95e04154eb to your computer and use it in GitHub Desktop.
Save fmedlin/69b442c90db4e928cf105b95e04154eb to your computer and use it in GitHub Desktop.

Revisions

  1. fmedlin revised this gist Nov 1, 2021. No changes.
  2. fmedlin created this gist Nov 1, 2021.
    31 changes: 31 additions & 0 deletions AnalyticsTrackerNosara.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    @Override
    public void track(AnalyticsTracker.Stat stat, String category, String label, Map<String, ?> properties) {
    if (mNosaraClient == null) {
    return;
    }

    String eventName = stat.name().toLowerCase();

    final String user;
    final TracksClient.NosaraUserType userType;
    if (mUserName != null) {
    user = mUserName;
    userType = TracksClient.NosaraUserType.SIMPLENOTE;
    } else {
    // This is just a security checks since the anonID is already available here.
    // refresh metadata is called on login/logout/startup and it loads/generates the anonId when necessary.
    if (getAnonID() == null) {
    user = generateNewAnonID();
    } else {
    user = getAnonID();
    }
    userType = TracksClient.NosaraUserType.ANON;
    }

    if (properties != null) {
    JSONObject propertiesJson = new JSONObject(properties);
    mNosaraClient.track(EVENTS_PREFIX + eventName, propertiesJson, user, userType);
    } else {
    mNosaraClient.track(EVENTS_PREFIX + eventName, user, userType);
    }
    }