Tracking iframe campaign clicks.

This commit is contained in:
DebaucheryLibrarian 2023-07-26 00:26:15 +02:00
parent f59429c30a
commit 7f74d227f0
2 changed files with 16 additions and 1 deletions

View File

@ -9,6 +9,8 @@
marginwidth="0"
marginheight="0"
class="campaign frame"
data-umami-event="campaign-click"
:data-umami-event-campaign-id="`${campaign.entity.slug}-${campaign.id}`"
/>
<a

View File

@ -96,17 +96,29 @@ function scrollToTop() {
this.$refs.content.scrollTop = 0;
}
function trackIframeCampaign() {
// no way to capture clicks from an iframe directly
if (window.umami && document.activeElement.tagName === 'IFRAME' && document.activeElement.dataset.umamiEvent === 'campaign-click') {
window.umami.track('campaign-click', {
'campaign-id': document.activeElement.dataset.umamiEventCampaignId,
});
}
}
function mounted() {
document.addEventListener('click', this.blur);
window.addEventListener('resize', this.resize);
this.events.on('toggleSettings', this.toggleSettings);
this.events.on('toggleSidebar', this.toggleSidebar);
window.addEventListener('blur', this.trackIframeCampaign);
}
function beforeUnmount() {
document.removeEventListener('click', this.blur);
window.removeEventListener('resize', this.resize);
window.removeEventListener('blur', this.trackIframeCampaign);
}
export default {
@ -129,10 +141,11 @@ export default {
mounted,
beforeUnmount,
methods: {
setConsent,
toggleSidebar,
toggleFilters,
toggleSettings,
setConsent,
trackIframeCampaign,
blur,
resize,
scroll,