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 axios from "axios";
|
||||||
|
import analyticsMixIn from "@/mixins/analytics-mixin.js";
|
||||||
|
|
||||||
import { applicationConfig } from "@/constants/application-config.js";
|
import { applicationConfig } from "@/constants/application-config.js";
|
||||||
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
||||||
import analyticsMixIn from "@/mixins/analytics-mixin.js";
|
|
||||||
import httpStatusCodes from "http-status-codes";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
callHttpClient({ method, endpoint, payload }) {
|
callHttpClient({ method, endpoint, payload, logApiCall = true }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const apiGatewayUrl = applicationConfig.CONSUMER_APIGATEWAY_URL;
|
const apiGatewayUrl = applicationConfig.CONSUMER_APIGATEWAY_URL;
|
||||||
const payloadAndAnalyticsData = Object.assign({}, payload, {
|
const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "FixMyGlass" });
|
||||||
AppName: "FixMyGlass",
|
|
||||||
});
|
|
||||||
|
|
||||||
axios({
|
axios({ method: method, url: apiGatewayUrl + endpoint, data: payloadAndAnalyticsData, crossDomain: true, responseType: {} })
|
||||||
method: method,
|
.then((response) => {
|
||||||
url: apiGatewayUrl + endpoint,
|
|
||||||
data: payloadAndAnalyticsData,
|
|
||||||
crossDomain: true,
|
|
||||||
responseType: {},
|
|
||||||
}).then(
|
|
||||||
(response) => {
|
|
||||||
if (response.status == httpStatusCodes.OK) {
|
|
||||||
if (response.data == undefined) {
|
|
||||||
|
|
||||||
analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT,
|
if (logApiCall) {
|
||||||
`${GaLabels.ERROR}_${endpoint}`, true);
|
analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT, `${GaLabels.SUCCESS}_${endpoint}`, true);
|
||||||
|
|
||||||
reject(response);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT,
|
|
||||||
`${GaLabels.SUCCESS}_${endpoint}`, true);
|
|
||||||
|
|
||||||
resolve(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
(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: {},
|
responseType: {},
|
||||||
}).then(
|
}).then(
|
||||||
(response) => {
|
(response) => {
|
||||||
if (response.status == httpStatusCodes.OK) {
|
resolve(response);
|
||||||
resolve(response);
|
|
||||||
} else {
|
|
||||||
reject(response);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
return reject(error.response);
|
return reject(error.response);
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,29 @@ import { experimentSettings } from "@/constants/experiments";
|
||||||
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents } from "@/constants/analytics";
|
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents } from "@/constants/analytics";
|
||||||
|
|
||||||
import baseMixin from "@/mixins/base-mixin";
|
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.
|
// We will need current page name for multiple methods, define it once to re-use.
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
logEvent(destinationFmgPageValue, pageEvent, category, action, label, value){
|
logEvent(pageEvent, category, action, label, value) {
|
||||||
var payload = {
|
var payload = {
|
||||||
userId: getDeviceIdValue(),
|
userId: getDeviceIdValue(),
|
||||||
sessionKey: getSessionKeyValue(),
|
sessionKey: getSessionKeyValue(),
|
||||||
pageName: destinationFmgPageValue,
|
pageName: currentPageName,
|
||||||
sessionId: getSessionIdValue(),
|
sessionId: getSessionIdValue(),
|
||||||
shouldUseSessionId: true,
|
shouldUseSessionId: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (pageEvent) {
|
if (pageEvent) {
|
||||||
payload.pageEvent = {action: '', event: pageEvent};
|
payload.pageEvent = { action: '', event: pageEvent };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category) {
|
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);
|
baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOG_ACTIVITY, payload, false);
|
||||||
|
|
@ -44,7 +46,7 @@ export default {
|
||||||
pushToDataLayerIfDefined(eventToBePushed);
|
pushToDataLayerIfDefined(eventToBePushed);
|
||||||
|
|
||||||
if (pushToLogApp) {
|
if (pushToLogApp) {
|
||||||
this.logEvent(currentPageName, undefined, category, action, label, undefined);
|
this.logEvent(undefined, category, action, label, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
@ -61,7 +63,7 @@ export default {
|
||||||
//this.logEvent(currentPageName, analyticsPageEvents.ENTRY);
|
//this.logEvent(currentPageName, analyticsPageEvents.ENTRY);
|
||||||
},
|
},
|
||||||
|
|
||||||
pushExperimentsToDataLayer(experiments){
|
pushExperimentsToDataLayer(experiments) {
|
||||||
experiments?.data?.forEach(exp => {
|
experiments?.data?.forEach(exp => {
|
||||||
|
|
||||||
// Set Google Dimension Index based on experiment settings.
|
// Set Google Dimension Index based on experiment settings.
|
||||||
|
|
@ -108,9 +110,9 @@ function pushToDataLayerIfDefined(data) {
|
||||||
function getPageNameByQueryString() {
|
function getPageNameByQueryString() {
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
|
|
||||||
if(params.has(queryStrings.FMG_PAGE)) {
|
if (params.has(queryStrings.FMG_PAGE)) {
|
||||||
return params.get(queryStrings.FMG_PAGE);
|
return params.get(queryStrings.FMG_PAGE);
|
||||||
}else{
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -442,7 +442,8 @@ export const actions = {
|
||||||
return globalMethods.callHttpClient({
|
return globalMethods.callHttpClient({
|
||||||
method: endpoints.LogActivity.method,
|
method: endpoints.LogActivity.method,
|
||||||
endpoint: endpoints.LogActivity.url,
|
endpoint: endpoints.LogActivity.url,
|
||||||
payload: payload
|
payload: payload,
|
||||||
|
logApiCall: false
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue