Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(non CFD): Matomo customDimensions error #558

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integrations/Matomo/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ class Matomo {
const trimmedEvent = event.toLowerCase().trim();

// For every type of track calls we consider the trackGoal function.
if (goalListMap.has(trimmedEvent)) {
if (goalListMap[trimmedEvent]) {
goalIdMapping(trimmedEvent, goalListMap, message);
}

// Mapping Standard Events
if (standardEventsMap.has(trimmedEvent)) {
if (standardEventsMap[trimmedEvent]) {
standardEventsMapping(trimmedEvent, standardEventsMap, message);
}

Expand Down
15 changes: 8 additions & 7 deletions integrations/Matomo/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import each from "@ndhoule/each";
import logger from "../../utils/logUtil";
import { getHashFromArray } from "../utils/commonUtils";
import { NAME } from "./constants";
Expand All @@ -9,15 +10,15 @@ import { NAME } from "./constants";
*/
const goalIdMapping = (event, goalListMap, message) => {
let revenue;
if (message.properties) revenue = message.properties.revenue;
goalListMap.forEach((val, key) => {
revenue = message.properties?.revenue;
each((val, key) => {
if (key === event) {
val.forEach((v) => {
if (revenue) window._paq.push(["trackGoal", v, revenue]);
else window._paq.push(["trackGoal", v]);
});
}
});
}, goalListMap);
};

/** Mapping Standard Events
Expand All @@ -27,7 +28,7 @@ const goalIdMapping = (event, goalListMap, message) => {
@param {} message
*/
const standardEventsMapping = (event, standardEventsMap, message) => {
standardEventsMap.forEach((val, key) => {
each((val, key) => {
if (key === event) {
let url;
let linkType;
Expand Down Expand Up @@ -132,7 +133,7 @@ const standardEventsMapping = (event, standardEventsMap, message) => {
}
});
}
});
}, standardEventsMap);
};

/** Mapping Ecommerce Events
Expand Down Expand Up @@ -344,9 +345,9 @@ const checkCustomDimensions = (message) => {
"dimensionId",
"dimensionValue"
);
customDimensionsMap.forEach((val, key) => {
each((val, key) => {
window._paq.push(["setCustomDimension", key, val]);
});
}, customDimensionsMap);
}
}
};
Expand Down
10 changes: 4 additions & 6 deletions integrations/utils/commonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ const getHashFromArrayWithDuplicate = (
toKey = "to",
isLowerCase = true
) => {
const hashMap = new Map();
const hashMap = {};
if (Array.isArray(arrays)) {
arrays.forEach((array) => {
if (!isNotEmpty(array[fromKey])) return;
const key = isLowerCase
? array[fromKey].toLowerCase().trim()
: array[fromKey].trim();

if (hashMap.has(key)) {
const valueArray = hashMap.get(key);
valueArray.push(array[toKey]);
hashMap.set(key, valueArray);
if (hashMap[key]) {
hashMap[key].push(array[toKey]);
} else {
hashMap.set(key, [array[toKey]]);
hashMap[key]= [array[toKey]];
}
});
}
Expand Down