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" marginwidth="0"
marginheight="0" marginheight="0"
class="campaign frame" class="campaign frame"
data-umami-event="campaign-click"
:data-umami-event-campaign-id="`${campaign.entity.slug}-${campaign.id}`"
/> />
<a <a

View File

@ -96,17 +96,29 @@ function scrollToTop() {
this.$refs.content.scrollTop = 0; 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() { function mounted() {
document.addEventListener('click', this.blur); document.addEventListener('click', this.blur);
window.addEventListener('resize', this.resize); window.addEventListener('resize', this.resize);
this.events.on('toggleSettings', this.toggleSettings); this.events.on('toggleSettings', this.toggleSettings);
this.events.on('toggleSidebar', this.toggleSidebar); this.events.on('toggleSidebar', this.toggleSidebar);
window.addEventListener('blur', this.trackIframeCampaign);
} }
function beforeUnmount() { function beforeUnmount() {
document.removeEventListener('click', this.blur); document.removeEventListener('click', this.blur);
window.removeEventListener('resize', this.resize); window.removeEventListener('resize', this.resize);
window.removeEventListener('blur', this.trackIframeCampaign);
} }
export default { export default {
@ -129,10 +141,11 @@ export default {
mounted, mounted,
beforeUnmount, beforeUnmount,
methods: { methods: {
setConsent,
toggleSidebar, toggleSidebar,
toggleFilters, toggleFilters,
toggleSettings, toggleSettings,
setConsent, trackIframeCampaign,
blur, blur,
resize, resize,
scroll, scroll,