Skip to content

Instantly share code, notes, and snippets.

@zation
Created October 18, 2017 08:17
Show Gist options
  • Save zation/c8e307f193a3f63c2354680ec937cf84 to your computer and use it in GitHub Desktop.
Save zation/c8e307f193a3f63c2354680ec937cf84 to your computer and use it in GitHub Desktop.
Analytics
(function () {
document.body.insertAdjacentHTML('beforeend', `
<style>
.AnalyticsContainer {
position: relative;
border: 3px solid red !important;
}
.AnalyticsContainer:hover > .Analytics {
display: block;
}
.Analytics {
position: absolute;
top: 0;
left: 0;
color: red;
text-align: left;
z-index: 99999;
display: none;
background: white;
padding: 6px;
white-space: nowrap;
}
</style>
`);
document
.querySelectorAll('[data-analyze-on="click"]')
.forEach((element) => {
element.classList.add('AnalyticsContainer');
element.insertAdjacentHTML('beforeend', `
<div class="Analytics">
<div>Category: ${element.getAttribute('data-event-category')}</div>
<div>Name: ${element.getAttribute('data-event-name')}</div>
<div>Label: ${element.getAttribute('data-event-label')}</div>
</div>
`);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment