Skip to content

Commit

Permalink
Merge pull request #75 from BA-Group/default-options
Browse files Browse the repository at this point in the history
Default options
  • Loading branch information
tjjalava authored Aug 24, 2017
2 parents a5a1703 + b8ef72a commit cc2bf74
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Application expects to find an object named `sizeme_options` (TODO: rename to `S
{
serviceStatus: true,
pluginVersion: "MAG1-0.1.0",
contextAddress: "https://sizeme.greitco.com",
gaTrackingId: "UA-40735596-2",
contextAddress: "https://sizeme.greitco.com"
shopType: "magento",
debugState: false,
uiOptions: {},
Expand All @@ -36,8 +35,6 @@ Application expects to find an object named `sizeme_options` (TODO: rename to `S

* [contextAddress] (_String_): URL to the SizeMe backend service.

* [gaTrackingId] (_String_): Google Analytics tracking id to be used when sending tracking events.

* [shopType] (_String_): webstore provider (magento|printmotor|pupeshop|woocommerce)

* [debugState] (_Boolean_): write debugging info to console. Default: false
Expand Down
37 changes: 18 additions & 19 deletions src/api/ga.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* global ga, sizeme_options */
const prodTrackingId = "UA-40735596-1";
const devTrackingId = "UA-40735596-2";

function loadGa (i, s, o, g, r) {
if (!i[r]) {
i["GoogleAnalyticsObject"] = r;
Expand All @@ -15,26 +18,22 @@ function loadGa (i, s, o, g, r) {
}
}

let gaTrackingId = sizeme_options.gaTrackingId;
let gaEnabled = !!gaTrackingId;
const gaTrackingId = !sizeme_options.debugState ? prodTrackingId : devTrackingId;
let trackEvent;

if (gaEnabled) {
loadGa(window, document, "script", "https://www.google-analytics.com/analytics.js", "ga");
loadGa(window, document, "script", "https://www.google-analytics.com/analytics.js", "ga");

trackEvent = (action, label) => {
ga("create", gaTrackingId, "auto", { name: "sizemeTracker" });
trackEvent = (a, l) => {
ga("sizemeTracker.send", {
hitType: "event",
eventCategory: window.location.hostname,
eventAction: a,
eventLabel: l + " (v3)"
});
};
trackEvent(action, label);
trackEvent = (action, label) => {
ga("create", gaTrackingId, "auto", { name: "sizemeTracker" });
trackEvent = (a, l) => {
ga("sizemeTracker.send", {
hitType: "event",
eventCategory: window.location.hostname,
eventAction: a,
eventLabel: l + " (v3)"
});
};
} else {
trackEvent = () => {};
}
export { trackEvent, gaEnabled };
trackEvent(action, label);
};

export { trackEvent };
11 changes: 4 additions & 7 deletions src/api/sizeme-api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global sizeme_options, sizeme_product */

import "isomorphic-fetch";
import { trackEvent, gaEnabled } from "./ga.js";
import { trackEvent } from "./ga.js";
import * as actions from "./actions";
import { createStore, applyMiddleware } from "redux";
import thunkMiddleware from "redux-thunk";
Expand All @@ -22,7 +22,7 @@ const storeMeasurementsKey = "sizemeMeasurements";
const sizemeStore = createStore(rootReducer, applyMiddleware(
thunkMiddleware,
createLogger({
predicate: sizeme_options.debugState,
predicate: () => !!sizeme_options.debugState,
duration: true
})
));
Expand Down Expand Up @@ -78,13 +78,10 @@ class FitRequest {

function createRequest (method, { token, withCredentials, body } = {}) {
const headers = new Headers({
"X-Sizeme-Pluginversion": pluginVersion
"X-Sizeme-Pluginversion": pluginVersion,
"X-Analytics-Enabled": true
});

if (gaEnabled) {
headers.append("X-Analytics-Enabled", true);
}

if (token) {
headers.append("Authorization", "Bearer " + token);
}
Expand Down

0 comments on commit cc2bf74

Please sign in to comment.