fix source formatting

This commit is contained in:
Damodar Lohani
2024-04-23 07:56:39 +00:00
parent 933353efc3
commit a41f604276
+6 -9
View File
@@ -22,25 +22,22 @@
window.VERCEL_ANALYTICS_ID = import.meta.env.VERCEL_ANALYTICS_ID?.toString() ?? false;
}
// Format source array to count source occurrences
let format = (arr) => {
const counts = {}; // Object to store the counts
const counts = {};
// Loop through each item in the array
arr.forEach((item) => {
// Increment the count for each key in the object
counts[item] = (counts[item] || 0) + 1;
const key = item.split(';')[0];
counts[key] = (counts[key] || 0) + 1;
});
// Convert counts object into the required string format array
const formattedArray = Object.entries(counts).map(([key, value]) => `${key},${value}`);
return formattedArray;
return Object.entries(counts).map(([key, count]) => `${key};${count}`);
};
onMount(async () => {
// handle sources
if (browser) {
const source = Cookies.get('source');
console.log(source);
let sources = source ? decodeURIComponent(source).split(',') : [];
console.log(sources);