package org.wikipedia.analytics;

import org.json.JSONException;
import org.json.JSONObject;
import org.wikipedia.Site;
import org.wikipedia.WikipediaApp;

public class ToCInteractionFunnel extends Funnel {
    private static final String SCHEMA_NAME = "MobileWikiAppToCInteraction";
    private static final int REV_ID = 10375484;

    private final String appInstallID;
    private final Site site;

    public ToCInteractionFunnel(WikipediaApp app, Site site) {
        super(app, SCHEMA_NAME, REV_ID);

        //Retrieve this app installation's unique ID, used to record unique users of features
        appInstallID = app.getAppInstallID();

        this.site = site;
    }

    @Override
    protected JSONObject preprocessData(JSONObject eventData) {
        try {
            eventData.put("appInstallID", appInstallID);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
        return eventData;
    }

    protected void log(Object... params) { super.log(site, params); }

    public void logOpen() {
        log(
                "action", "open"
        );
    }

    public void logClose() {
        log(
                "action", "close"
        );
    }

    public void logClick() {
        log(
                "action", "click"
        );
    }
}

@@ -320,15 +320,15 @@
  = 1
-0375484
+1014396
 ;%0A%0A 
@@ -991,33 +991,742 @@
 s) %7B
- super.log(site, params);
+%0A        final int defaultSampleRate = 100;%0A%0A        //get our sampling rate from remote config%0A        int sampleRate = WikipediaApp.getInstance().getRemoteConfig().getConfig()%0A                .optInt(%22tocLogSampleRate%22, defaultSampleRate);%0A%0A        if (sampleRate != 0) %7B%0A            //take the last 4 hex digits of the uuid, modulo the sampling coefficient.%0A            //if the result is 0, then we're one of the Chosen.%0A            final int uuidSubstrLen = 4;%0A            final int hexBase = 16;%0A            boolean chosen = Integer.parseInt(appInstallID.substring(appInstallID.length() - uuidSubstrLen), hexBase) %25 sampleRate == 0;%0A%0A            if (chosen) %7B%0A                super.log(site, params);%0A            %7D%0A        %7D%0A   
  %7D%0A%0A

Add 1:100 sampling rate for table of contents interaction.