Skip to content

Commit

Permalink
Remove unused analytics (getodk#2964)
Browse files Browse the repository at this point in the history
* ExternalData generates a lot of hits and we have enough data to act on deprecation

* Itemset hits are not needed because current() migration has finished

* AuditLogging hits are not actionable

* Enough data on selected splash image has been collected to decide on deprecation
  • Loading branch information
yanokwa authored and grzesiek2010 committed Mar 27, 2019
1 parent 7da533d commit 92ab6b1
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import android.widget.Toast;

import com.google.android.gms.analytics.HitBuilders;

import org.javarosa.core.model.SelectChoice;
import org.javarosa.core.model.condition.EvaluationContext;
import org.javarosa.core.model.instance.FormInstance;
Expand Down Expand Up @@ -110,12 +108,6 @@ public static XPathFuncExpr getSearchXPathExpression(String appearance) {

Matcher matcher = SEARCH_FUNCTION_REGEX.matcher(appearance);
if (matcher.find()) {
Collect.getInstance().getDefaultTracker()
.send(new HitBuilders.EventBuilder()
.setCategory("ExternalData")
.setAction("search()")
.setLabel(Collect.getCurrentFormIdentifierHash())
.build());

String function = matcher.group(0);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;

import com.google.android.gms.analytics.HitBuilders;

import org.javarosa.core.model.condition.EvaluationContext;
import org.javarosa.xpath.expr.XPathFuncExpr;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.external.ExternalDataManager;
import org.odk.collect.android.external.ExternalDataUtil;
import org.odk.collect.android.external.ExternalSQLiteOpenHelper;
Expand Down Expand Up @@ -71,12 +68,6 @@ public boolean realTime() {

@Override
public Object eval(Object[] args, EvaluationContext ec) {
Collect.getInstance().getDefaultTracker()
.send(new HitBuilders.EventBuilder()
.setCategory("ExternalData")
.setAction("pulldata()")
.setLabel(Collect.getCurrentFormIdentifierHash())
.build());

if (args.length != 4) {
Timber.e("4 arguments are needed to evaluate the %s function", HANDLER_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.google.android.gms.analytics.HitBuilders;

import org.javarosa.core.model.CoreModelModule;
import org.javarosa.core.model.FormDef;
import org.javarosa.core.model.FormIndex;
Expand Down Expand Up @@ -49,7 +47,6 @@
import org.javarosa.xform.parse.XFormParser;
import org.javarosa.xpath.XPathParseTool;
import org.javarosa.xpath.expr.XPathExpression;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.exception.JavaRosaException;
import org.odk.collect.android.utilities.AuditEventLogger;
import org.odk.collect.android.utilities.RegexUtils;
Expand Down Expand Up @@ -1220,12 +1217,6 @@ public InstanceMetadata getSubmissionMetadata() {
// timing element...
v = e.getChildrenWithName(AUDIT);
if (v.size() == 1) {
Collect.getInstance().getDefaultTracker()
.send(new HitBuilders.EventBuilder()
.setCategory("AuditLogging")
.setAction("Enabled")
.setLabel(Collect.getCurrentFormIdentifierHash())
.build());

TreeElement auditElement = v.get(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@
import android.support.annotation.Nullable;
import android.view.View;

import com.google.android.gms.analytics.HitBuilders;
import com.google.common.collect.ObjectArrays;

import org.odk.collect.android.R;
import org.odk.collect.android.activities.MainMenuActivity;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.spatial.MapHelper;
import org.odk.collect.android.utilities.FileUtils;
import org.odk.collect.android.utilities.LocaleHelper;
import org.odk.collect.android.utilities.MediaUtils;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.TreeMap;

Expand Down Expand Up @@ -264,17 +260,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
String sourceMediaPath = MediaUtils.getPathFromUri(getActivity(), selectedMedia,
MediaStore.Images.Media.DATA);

String sourceMediaPathHash = FileUtils.getMd5Hash(new ByteArrayInputStream(sourceMediaPath.getBytes()));

// setting image path
setSplashPath(sourceMediaPath);

Collect.getInstance().getDefaultTracker()
.send(new HitBuilders.EventBuilder()
.setCategory("PreferenceChange")
.setAction("Selected splash image")
.setLabel(sourceMediaPathHash)
.build());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@

import android.content.Context;

import com.google.android.gms.analytics.HitBuilders;

import org.javarosa.core.model.Constants;
import org.javarosa.core.model.ItemsetBinding;
import org.javarosa.core.model.QuestionDef;
import org.javarosa.form.api.FormEntryPrompt;
import org.javarosa.xpath.expr.XPathExpression;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.external.ExternalDataUtil;

import java.util.List;
import java.util.Locale;

import timber.log.Timber;
Expand Down Expand Up @@ -130,13 +123,6 @@ public static QuestionWidget createWidgetFromPrompt(FormEntryPrompt fep, Context
String query = fep.getQuestion().getAdditionalAttribute(null, "query");
if (query != null) {
questionWidget = new ItemsetWidget(context, fep, appearance.startsWith("quick"));

Collect.getInstance().getDefaultTracker()
.send(new HitBuilders.EventBuilder()
.setCategory("ExternalData")
.setAction("External itemset")
.setLabel(Collect.getCurrentFormIdentifierHash())
.build());
} else if (appearance.startsWith("printer")) {
questionWidget = new ExPrinterWidget(context, fep);
} else if (appearance.startsWith("ex:")) {
Expand Down Expand Up @@ -217,7 +203,6 @@ public static QuestionWidget createWidgetFromPrompt(FormEntryPrompt fep, Context
} else {
questionWidget = new SelectOneWidget(context, fep, appearance.contains("quick"));
}
logChoiceFilterAnalytics(fep.getQuestion());
break;
case Constants.CONTROL_SELECT_MULTI:
// search() appearance/function (not part of XForms spec) added by SurveyCTO gets
Expand Down Expand Up @@ -253,7 +238,6 @@ public static QuestionWidget createWidgetFromPrompt(FormEntryPrompt fep, Context
} else {
questionWidget = new SelectMultiWidget(context, fep);
}
logChoiceFilterAnalytics(fep.getQuestion());
break;
case Constants.CONTROL_RANK:
questionWidget = new RankingWidget(context, fep);
Expand Down Expand Up @@ -286,35 +270,4 @@ public static QuestionWidget createWidgetFromPrompt(FormEntryPrompt fep, Context

return questionWidget;
}

/**
* Log analytics event each time a question with a choice filter is accessed, identifying
* choice filters with relative expressions. This was initially introduced to inform messaging
* around a long-standing bug in JavaRosa: https://github.com/opendatakit/javarosa/issues/293
*/
private static void logChoiceFilterAnalytics(QuestionDef question) {
ItemsetBinding itemsetBinding = question.getDynamicChoices();

if (itemsetBinding != null && itemsetBinding.nodesetRef != null) {
if (itemsetBinding.nodesetRef.hasPredicates()) {
for (int level = 0; level < itemsetBinding.nodesetRef.size(); level++) {
List<XPathExpression> predicates = itemsetBinding.nodesetRef.getPredicate(level);

if (predicates != null) {
for (XPathExpression predicate : predicates) {
String actionName = predicate.toString().contains("func-expr:current") ?
"CurrentPredicate" : "NonCurrentPredicate";

Collect.getInstance().getDefaultTracker()
.send(new HitBuilders.EventBuilder()
.setCategory("Itemset")
.setAction(actionName)
.setLabel(Collect.getCurrentFormIdentifierHash())
.build());
}
}
}
}
}
}
}

0 comments on commit 92ab6b1

Please sign in to comment.