Skip to content

Commit

Permalink
checking if google analytics account is configured before tracking it
Browse files Browse the repository at this point in the history
  • Loading branch information
luis100 committed Feb 26, 2019
1 parent 2f1ea9d commit a2add8d
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.roda.core.data.common.RodaConstants;
import org.roda.wui.common.client.tools.ConfigurationManager;
import org.roda.wui.common.client.tools.StringUtils;

public class GAnalyticsTracker {

Expand All @@ -27,19 +28,22 @@ private GAnalyticsTracker() {
* @param historyToken
*/
public static void track(String historyToken) {
final String page = "/#" + historyToken;

if (accountId == null) {
if (StringUtils.isBlank(accountId)) {
accountId = ConfigurationManager.getString(RodaConstants.UI_GOOGLE_ANALYTICS_CODE_PROPERTY);
setAccount(accountId);
if (StringUtils.isNotBlank(accountId)) {
setAccount(accountId);
}
}

pageview(page);
if (StringUtils.isNotBlank(accountId)) {
pageview("/#" + historyToken);
}
}

private static native void setAccount(String accountId)
/*-{
$wnd.ga('create', accountId, 'auto');
$wnd.ga('create', accountId, 'auto');
}-*/;

/**
Expand All @@ -49,8 +53,8 @@ private static native void setAccount(String accountId)
*/
private static native void pageview(String page)
/*-{
$wnd.ga('set', 'page', page);
$wnd.ga('send', 'pageview');
$wnd.ga('set', 'page', page);
$wnd.ga('send', 'pageview');
}-*/;

}

0 comments on commit a2add8d

Please sign in to comment.