package codeOrchestra.colt.core.tracker;

import codeOrchestra.util.FingerprintUtil;
import com.dmurph.tracking.AnalyticsConfigData;
import com.dmurph.tracking.JGoogleAnalyticsTracker;
import com.dmurph.tracking.VisitorData;
import com.dmurph.tracking.system.AWTSystemPopulator;

/**
 * @author Dima Kruk
 */
public class GATracker {
    private static GATracker ourInstance = new GATracker();

    private JGoogleAnalyticsTracker tracker;

    private final String hostName = "code-orchestra.github.io";
    private String refPage = "/";


    public static GATracker getInstance() {
        return ourInstance;
    }

    private GATracker() {
        JGoogleAnalyticsTracker.setProxy(System.getenv("http_proxy"));
        int UUID = FingerprintUtil.getNumericFingerPrint();
        VisitorData visitorData = VisitorData.newVisitor(UUID);
        //TODO: replace with production TrackingCode
        AnalyticsConfigData config = new AnalyticsConfigData("UA-42969501-5", visitorData);
        AWTSystemPopulator.populateConfigData(config);

        tracker = new JGoogleAnalyticsTracker(config, JGoogleAnalyticsTracker.GoogleAnalyticsVersion.V_4_7_2);
    }

    public void trackEvent(String argCategory, String argAction) {
        tracker.trackEvent(argCategory, argAction);
    }

    public void trackPageView(String argPageURL, String argPageTitle) {
        tracker.trackPageViewFromReferrer(argPageURL, argPageTitle, hostName, hostName, refPage);
        refPage = argPageURL;
    }
}

@@ -122,24 +122,73 @@
 ConfigData;%0A
+import com.dmurph.tracking.AnalyticsRequestData;%0A
 import com.d
@@ -547,16 +547,51 @@
 ub.io%22;%0A
+    private String prevPage = %22/%22;%0A
     priv
@@ -608,21 +608,25 @@
  refPage
+Title
  = %22
-/
 %22;%0A%0A%0A   
@@ -1359,32 +1359,448 @@
 Action);%0A    %7D%0A%0A
+    public void trackEventWithPage(String argCategory, String argAction) %7B%0A        AnalyticsRequestData data = new AnalyticsRequestData();%0A        data.setEventCategory(argCategory);%0A        data.setEventAction(argAction);%0A        data.setEventLabel(null);%0A        data.setEventValue(null);%0A        data.setPageTitle(refPageTitle);%0A        data.setPageURL(prevPage);%0A%0A        tracker.makeCustomRequest(data);%0A    %7D%0A%0A
     public void 
@@ -1943,19 +1943,20 @@
 stName, 
+p
 re
-f
+v
 Page);%0A 
@@ -1962,19 +1962,20 @@
         
+p
 re
-f
+v
 Page = a

add page info for tracking events