package org.wikipedia.analytics;

import android.content.Context;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;

import org.json.JSONObject;
import org.wikipedia.WikipediaApp;
import org.wikipedia.util.StringUtil;

import java.util.concurrent.TimeUnit;

// https://meta.wikimedia.org/wiki/Schema:MobileWikiAppDailyStats
public class DailyStatsFunnel extends Funnel {
    private static final String SCHEMA_NAME = "MobileWikiAppDailyStats";
    private static final int SCHEMA_REVISION = 18115101;

    public DailyStatsFunnel(WikipediaApp app) {
        super(app, SCHEMA_NAME, SCHEMA_REVISION, Funnel.SAMPLE_LOG_100);
    }

    public void log(Context context) {
        log(getInstallAgeDays(context));
    }

    public void log(long appInstallAgeDays) {
        log("appInstallAgeDays", appInstallAgeDays,
                "languages", StringUtil.listToJsonArrayString(getApp().language().getAppLanguageCodes()));
    }

    @Override protected void preprocessSessionToken(@NonNull JSONObject eventData) { }

    private long getInstallAgeDays(Context context) {
        return TimeUnit.MILLISECONDS.toDays(getInstallAge(context));
    }

    private long getInstallAge(Context context) {
        return getAbsoluteTime() - getInstallTime(context);
    }

    /** @return The absolute time since initial app install in milliseconds. */
    private long getInstallTime(Context context) {
        try {
            return context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0)
                    .firstInstallTime;
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    private long getAbsoluteTime() {
        return System.currentTimeMillis();
    }
}

@@ -208,16 +208,55 @@
 diaApp;%0A
+import org.wikipedia.auth.AccountUtil;%0A
 import o
@@ -748,16 +748,37 @@
     log(
+%22appInstallAgeDays%22, 
 getInsta
@@ -799,114 +799,8 @@
 ext)
-);%0A    %7D%0A%0A    public void log(long appInstallAgeDays) %7B%0A        log(%22appInstallAgeDays%22, appInstallAgeDays
 ,%0A  
@@ -901,16 +901,77 @@
 Codes())
+,%0A                %22is_anon%22, AccountUtil.isLoggedIn() ? 0 : 1
 );%0A    %7D

Add missing is_anon parameter to DailyStats event.