Analytics Scripts Improvements for RHDC #682
Replies: 3 comments
-
So here's a prototype. @rmessickSDI please paste this into the console on RHDC and start clicking on stuff. Let me know what I'm missing here. const isAnalyticsEntry = ([x]) => x.startsWith('analytics');
const lowercaseFirst = x => `${x.charAt(0).toLowerCase()}${x.slice(1)}`;
const eddlClickPathReducer = (acc, node) => {
if (node instanceof Element) {
for (const [k, v] of Object.entries(node.dataset).filter(isAnalyticsEntry)) {
const key = lowercaseFirst(k.replace('analytics', ''));
if (!acc[key])
acc[key] = v;
else
acc[key] = `${acc[key]}|${v}`;
}
}
return acc;
}
document.addEventListener('click', function(event) {
event.preventDefault();
const payload = event.composedPath().reduceRight(eddlClickPathReducer, {});
console.log(payload);
}); |
Beta Was this translation helpful? Give feedback.
-
@bennypowers I am liking your approach here. Is there a way to get the source
|
Beta Was this translation helpful? Give feedback.
-
Yes I believe so, but conversely, we've discussed in the past offloading this to the HTML, which I think is wise: only data attributes get sent along |
Beta Was this translation helpful? Give feedback.
-
NB: this issue is not strictly related to RHDS, but we're tracking it here anyways
The Plan
Next Steps
Synchronize your watches..... now!
cc @markcaron @clt2rdu
Beta Was this translation helpful? Give feedback.
All reactions