package org.jboss.as.console.client.analytics;

import com.google.gwt.core.client.GWT;
import com.google.inject.Provider;
import com.gwtplatform.mvp.client.googleanalytics.GoogleAnalytics;
import org.jboss.as.console.client.shared.Preferences;

/**
 * @author Heiko Braun
 * @date 10/24/12
 */
public class AnalyticsProvider implements Provider<GoogleAnalytics> {

    private GoogleAnalytics delegate;
    private static final GoogleAnalytics NOOP = new NoopAnalytics();

    @Override
    public GoogleAnalytics get() {

        GoogleAnalytics analytics = null;

        if(!Preferences.has(Preferences.Key.ANALYTICS) // not set at all
            || Preferences.get(Preferences.Key.ANALYTICS).equals("true")
                && GWT.isScript() ) // web mode only
        {
            analytics = new CustomAnalyticsImpl();
            System.out.println("Google analytics is setup");
        }
        else
        {
            System.out.println("Running stub analytics implementation");
            analytics = NOOP;
        }

        return analytics;
    }
    
    static class NoopAnalytics implements GoogleAnalytics
    {
        @Override
        public void init(String userAccount) {
            
        }

        @Override
        public void addAccount(String trackerName, String userAccount) {
            
        }

        @Override
        public void trackPageview() {
            
        }

        @Override
        public void trackPageview(String pageName) {
            
        }

        @Override
        public void trackPageview(String trackerName, String pageName) {
            
        }

        @Override
        public void trackEvent(String category, String action) {
            
        }

        @Override
        public void trackEventWithTracker(String trackerName, String category, String action) {
            
        }

        @Override
        public void trackEvent(String category, String action, String optLabel) {
            
        }

        @Override
        public void trackEventWithTracker(String trackerName, String category, String action, String optLabel) {
            
        }

        @Override
        public void trackEvent(String category, String action, String optLabel, int optValue) {
            
        }

        @Override
        public void trackEventWithTracker(String trackerName, String category, String action, String optLabel, int optValue) {
            
        }

        @Override
        public void trackEvent(String category, String action, String optLabel, int optValue, boolean optNonInteraction) {
            
        }

        @Override
        public void trackEventWithTracker(String trackerName, String category, String action, String optLabel, int optValue, boolean optNonInteraction) {
            
        }
    }
}

@@ -182,16 +182,58 @@
 lytics;%0A
+import org.jboss.as.console.client.Build;%0A
 import o
@@ -279,16 +279,16 @@
 rences;%0A
-
 %0A/**%0A * 
@@ -613,11 +613,67 @@
     
-if(
+// no preferences == enabled%0A        boolean prefEnabled = 
 !Pre
@@ -715,27 +715,13 @@
 ICS)
- // not set at all%0A
+%0A    
     
@@ -788,16 +788,18 @@
 (%22true%22)
+;%0A
 %0A       
@@ -803,52 +803,219 @@
     
-        && GWT.isScript() ) // web mode only
+// disabled for EAP by default%0A        boolean isEAP = Build.PROFILE.equalsIgnoreCase(%22eap%22);%0A%0A        // web mode only%0A        boolean isWebMode = GWT.isScript();%0A%0A        if(!isEAP && prefEnabled && isWebMode)
 %0A   

disable analytics for EAP builds