Merge pull request #389 from Safelite/feature/CSR-33
adjusted endpoint and logic
This commit is contained in:
commit
80a2d18c54
6 changed files with 40 additions and 23 deletions
|
|
@ -75,8 +75,8 @@ const endpoints = {
|
|||
url: "/analytics/api/v1/analytics/activity",
|
||||
method: "POST",
|
||||
},
|
||||
GetExperimentsByUserForGa: {
|
||||
url: "/analytics/api/v1/analytics/get-experiments-for-GA",
|
||||
GetExperimentsByUser: {
|
||||
url: "/analytics/api/v1/analytics/get-experiments",
|
||||
method: "GET",
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ const storeActions = {
|
|||
VALIDATE_ZIP: "validateZip",
|
||||
LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure",
|
||||
LOG_ACTIVITY: "logActivity",
|
||||
GET_EXPERIMENTS_BY_USER_FOR_GA: "getExperimentsByUserForGa",
|
||||
GET_EXPERIMENTS_BY_USER: "GetExperimentsByUser",
|
||||
|
||||
// DEPENDENCY MUTATIONS
|
||||
RESET_VEHICLE_STATE_AND_DEPENDENCIES: "resetVehicleAndDependencies",
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ export default {
|
|||
},
|
||||
|
||||
pushExperimentsToDataLayer(experiments) {
|
||||
experiments?.data?.forEach(exp => {
|
||||
experiments?.forEach(exp => {
|
||||
|
||||
// Set Google Dimension Index based on experiment settings.
|
||||
let googleDimensionIndex = 99;
|
||||
|
|
@ -72,11 +72,13 @@ export default {
|
|||
}
|
||||
|
||||
// Create object with dimension index and value.
|
||||
const experimentWithDimension = {};
|
||||
|
||||
Object.keys(exp).forEach(key => {
|
||||
experimentWithDimension[`${key}_${googleDimensionIndex}`] = exp[key];
|
||||
});
|
||||
const experimentWithDimension = {
|
||||
[`experimentId_${googleDimensionIndex}`]: exp.universeId,
|
||||
[`variationId_${googleDimensionIndex}`]: exp.variationId,
|
||||
[`experimentName_${googleDimensionIndex}`]: exp.universeName,
|
||||
[`variationName_${googleDimensionIndex}`]: exp.variationName,
|
||||
[`customDimension_${googleDimensionIndex}`]: `${exp.universeId}_${exp.variationId}_${exp.universeName}_${exp.variationName}`
|
||||
};
|
||||
|
||||
// Push to the data layer with the Google Custom Dimension Index.
|
||||
pushToDataLayerIfDefined(experimentWithDimension);
|
||||
|
|
|
|||
|
|
@ -40,21 +40,27 @@ describe("analyticsMixin.js", () => {
|
|||
// Arrange
|
||||
window.dataLayer = [];
|
||||
|
||||
const mockExperimentData = {
|
||||
data: [
|
||||
const mockExperimentData =
|
||||
[
|
||||
{
|
||||
settings: {},
|
||||
variationName: 'test',
|
||||
universeName: 'testUniverse'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
// Act
|
||||
analyticsMixin.methods.pushExperimentsToDataLayer(mockExperimentData);
|
||||
|
||||
// Assert
|
||||
expect(window.dataLayer).toEqual([ { settings_99: {}, variationName_99: 'test', universeName_99: 'testUniverse' } ]);
|
||||
expect(window.dataLayer).toEqual([{
|
||||
experimentId_99: undefined,
|
||||
variationId_99: undefined,
|
||||
experimentName_99: 'testUniverse',
|
||||
variationName_99: 'test',
|
||||
customDimension_99: 'undefined_undefined_testUniverse_test'
|
||||
}]);
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -62,21 +68,27 @@ describe("analyticsMixin.js", () => {
|
|||
// Arrange
|
||||
window.dataLayer = [];
|
||||
|
||||
const mockExperimentData = {
|
||||
data: [
|
||||
const mockExperimentData =
|
||||
[
|
||||
{
|
||||
settings: { "Google Custom Dimension Index": "5"},
|
||||
settings: { "Google Custom Dimension Index": "5" },
|
||||
variationName: 'test',
|
||||
universeName: 'testUniverse'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
// Act
|
||||
analyticsMixin.methods.pushExperimentsToDataLayer(mockExperimentData);
|
||||
|
||||
// Assert
|
||||
expect(window.dataLayer).toEqual([ { settings_5: {"Google Custom Dimension Index": "5"}, variationName_5: 'test', universeName_5: 'testUniverse' } ]);
|
||||
expect(window.dataLayer).toEqual([{
|
||||
experimentId_5: undefined,
|
||||
variationId_5: undefined,
|
||||
experimentName_5: 'testUniverse',
|
||||
variationName_5: 'test',
|
||||
customDimension_5: 'undefined_undefined_testUniverse_test'
|
||||
}]);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
@ -127,8 +127,11 @@ router.afterEach(async (to, from) => {
|
|||
// Push page view to GA
|
||||
analyticsMixin.methods.pushPageViewToGA(to.query[queryStrings.FMG_PAGE]);
|
||||
|
||||
const assignedExperiments = await baseMixin.methods.dispatchStoreAction(storeActions.GET_EXPERIMENTS_BY_USER_FOR_GA, { userId: getDeviceIdValue() });
|
||||
analyticsMixin.methods.pushExperimentsToDataLayer(assignedExperiments);
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.GET_EXPERIMENTS_BY_USER, { userId: getDeviceIdValue() })
|
||||
.then( (response) => {
|
||||
analyticsMixin.methods.pushExperimentsToDataLayer(response.data);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
router.navigate = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) => {
|
||||
|
|
|
|||
|
|
@ -459,10 +459,10 @@ export const actions = {
|
|||
});
|
||||
},
|
||||
|
||||
getExperimentsByUserForGa(context, { userId }){
|
||||
GetExperimentsByUser(context, { userId }){
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetExperimentsByUserForGa.method,
|
||||
endpoint: `${endpoints.GetExperimentsByUserForGa.url}/${userId}`,
|
||||
method: endpoints.GetExperimentsByUser.method,
|
||||
endpoint: `${endpoints.GetExperimentsByUser.url}/${userId}`,
|
||||
payload: {}
|
||||
});
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue