Log Events to LogApp
This commit is contained in:
parent
a638f63cdd
commit
121a7dbcb2
3 changed files with 41 additions and 57 deletions
|
|
@ -1,49 +1,34 @@
|
|||
import axios from "axios";
|
||||
import analyticsMixIn from "@/mixins/analytics-mixin.js";
|
||||
|
||||
import { applicationConfig } from "@/constants/application-config.js";
|
||||
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
||||
import analyticsMixIn from "@/mixins/analytics-mixin.js";
|
||||
import httpStatusCodes from "http-status-codes";
|
||||
|
||||
export default {
|
||||
callHttpClient({ method, endpoint, payload }) {
|
||||
callHttpClient({ method, endpoint, payload, logApiCall = true }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const apiGatewayUrl = applicationConfig.CONSUMER_APIGATEWAY_URL;
|
||||
const payloadAndAnalyticsData = Object.assign({}, payload, {
|
||||
AppName: "FixMyGlass",
|
||||
});
|
||||
const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "FixMyGlass" });
|
||||
|
||||
axios({
|
||||
method: method,
|
||||
url: apiGatewayUrl + endpoint,
|
||||
data: payloadAndAnalyticsData,
|
||||
crossDomain: true,
|
||||
responseType: {},
|
||||
}).then(
|
||||
(response) => {
|
||||
if (response.status == httpStatusCodes.OK) {
|
||||
if (response.data == undefined) {
|
||||
axios({ method: method, url: apiGatewayUrl + endpoint, data: payloadAndAnalyticsData, crossDomain: true, responseType: {} })
|
||||
.then((response) => {
|
||||
|
||||
analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT,
|
||||
`${GaLabels.ERROR}_${endpoint}`, true);
|
||||
|
||||
reject(response);
|
||||
} else {
|
||||
|
||||
analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT,
|
||||
`${GaLabels.SUCCESS}_${endpoint}`, true);
|
||||
|
||||
resolve(response);
|
||||
}
|
||||
if (logApiCall) {
|
||||
analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT, `${GaLabels.SUCCESS}_${endpoint}`, true);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error(error);
|
||||
analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT,
|
||||
`${GaLabels.ERROR}_${endpoint}`, true);
|
||||
|
||||
return reject(error.response);
|
||||
}
|
||||
);
|
||||
return resolve(response);
|
||||
},
|
||||
error => {
|
||||
console.error(error);
|
||||
|
||||
if (logApiCall) {
|
||||
analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT, `${GaLabels.ERROR}_${endpoint}`, true);
|
||||
}
|
||||
|
||||
return reject(error.response);
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -58,11 +43,7 @@ export default {
|
|||
responseType: {},
|
||||
}).then(
|
||||
(response) => {
|
||||
if (response.status == httpStatusCodes.OK) {
|
||||
resolve(response);
|
||||
} else {
|
||||
reject(response);
|
||||
}
|
||||
resolve(response);
|
||||
},
|
||||
(error) => {
|
||||
return reject(error.response);
|
||||
|
|
|
|||
|
|
@ -5,29 +5,31 @@ import { experimentSettings } from "@/constants/experiments";
|
|||
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents } from "@/constants/analytics";
|
||||
|
||||
import baseMixin from "@/mixins/base-mixin";
|
||||
import { applicationConfig } from "@/constants/application-config.js";
|
||||
import axios from "axios";
|
||||
|
||||
// We will need current page name for multiple methods, define it once to re-use.
|
||||
const currentPageName = getPageNameByQueryString();
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
logEvent(destinationFmgPageValue, pageEvent, category, action, label, value){
|
||||
logEvent(pageEvent, category, action, label, value) {
|
||||
var payload = {
|
||||
userId: getDeviceIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: destinationFmgPageValue,
|
||||
pageName: currentPageName,
|
||||
sessionId: getSessionIdValue(),
|
||||
shouldUseSessionId: true,
|
||||
};
|
||||
|
||||
if (pageEvent) {
|
||||
payload.pageEvent = {action: '', event: pageEvent};
|
||||
payload.pageEvent = { action: '', event: pageEvent };
|
||||
}
|
||||
|
||||
if (category) {
|
||||
payload.customEvent = {category: category, action: action, label: label, value: value};
|
||||
payload.customEvent = { category: category, action: action, label: label, value: value };
|
||||
}
|
||||
|
||||
|
||||
baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOG_ACTIVITY, payload, false);
|
||||
},
|
||||
|
||||
|
|
@ -42,9 +44,9 @@ export default {
|
|||
}
|
||||
|
||||
pushToDataLayerIfDefined(eventToBePushed);
|
||||
|
||||
|
||||
if (pushToLogApp) {
|
||||
this.logEvent(currentPageName, undefined, category, action, label, undefined);
|
||||
this.logEvent(undefined, category, action, label, undefined);
|
||||
}
|
||||
|
||||
},
|
||||
|
|
@ -57,27 +59,27 @@ export default {
|
|||
};
|
||||
|
||||
pushToDataLayerIfDefined(pageViewEvent);
|
||||
|
||||
|
||||
//this.logEvent(currentPageName, analyticsPageEvents.ENTRY);
|
||||
},
|
||||
|
||||
pushExperimentsToDataLayer(experiments){
|
||||
pushExperimentsToDataLayer(experiments) {
|
||||
experiments?.data?.forEach(exp => {
|
||||
|
||||
|
||||
// Set Google Dimension Index based on experiment settings.
|
||||
let googleDimensionIndex = 99;
|
||||
|
||||
|
||||
if (exp.settings[experimentSettings.GOOGLE_CUSTOM_DIMENSION_INDEX] !== undefined) {
|
||||
googleDimensionIndex = exp.settings[experimentSettings.GOOGLE_CUSTOM_DIMENSION_INDEX];
|
||||
}
|
||||
|
||||
|
||||
// Create object with dimension index and value.
|
||||
const experimentWithDimension = {};
|
||||
|
||||
|
||||
Object.keys(exp).forEach(key => {
|
||||
experimentWithDimension[`${key}_${googleDimensionIndex}`] = exp[key];
|
||||
});
|
||||
|
||||
|
||||
// Push to the data layer with the Google Custom Dimension Index.
|
||||
pushToDataLayerIfDefined(experimentWithDimension);
|
||||
});
|
||||
|
|
@ -108,9 +110,9 @@ function pushToDataLayerIfDefined(data) {
|
|||
function getPageNameByQueryString() {
|
||||
const params = new URLSearchParams(location.search);
|
||||
|
||||
if(params.has(queryStrings.FMG_PAGE)) {
|
||||
if (params.has(queryStrings.FMG_PAGE)) {
|
||||
return params.get(queryStrings.FMG_PAGE);
|
||||
}else{
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
@ -442,7 +442,8 @@ export const actions = {
|
|||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LogActivity.method,
|
||||
endpoint: endpoints.LogActivity.url,
|
||||
payload: payload
|
||||
payload: payload,
|
||||
logApiCall: false
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue