From 47375d4eeb5565bf7e265d55f31970e072350e83 Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Fri, 26 Oct 2018 00:32:43 +0200 Subject: [PATCH 1/3] Prevent send pageview without params --- app/bundles/PageBundle/EventListener/BuildJsSubscriber.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/bundles/PageBundle/EventListener/BuildJsSubscriber.php b/app/bundles/PageBundle/EventListener/BuildJsSubscriber.php index 6c8692b8953..aa6bc9e3c56 100644 --- a/app/bundles/PageBundle/EventListener/BuildJsSubscriber.php +++ b/app/bundles/PageBundle/EventListener/BuildJsSubscriber.php @@ -241,7 +241,9 @@ function() { // Process pageviews after new are added document.addEventListener('eventAddedToMauticQueue', function(e) { - m.sendPageview(e.detail); + if(e.detail[0] == 'send' && e.detail[1] == 'pageview'){ + m.sendPageview(e.detail); + } }); })(MauticJS, location, navigator, document); JS; From 9ece25b35c8f3753e28be7f2ae07cda60573c371 Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Sun, 4 Nov 2018 07:38:01 +0100 Subject: [PATCH 2/3] Add new ensureEventContext --- app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php | 6 ++++++ app/bundles/PageBundle/EventListener/BuildJsSubscriber.php | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php b/app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php index 75e8c6b1e04..1c45617db61 100644 --- a/app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php +++ b/app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php @@ -423,6 +423,12 @@ enumerable: false, return matches; } } + +MauticJS.ensureEventContext = function(event, context0, context1) { // + return event.hasOwnProperty('detail') + && event.detail[0] === context0 + && event.detail[1] === context1; +}; JS; $event->appendJs($js, 'Mautic Core'); } diff --git a/app/bundles/PageBundle/EventListener/BuildJsSubscriber.php b/app/bundles/PageBundle/EventListener/BuildJsSubscriber.php index aa6bc9e3c56..d0685ad2832 100644 --- a/app/bundles/PageBundle/EventListener/BuildJsSubscriber.php +++ b/app/bundles/PageBundle/EventListener/BuildJsSubscriber.php @@ -241,8 +241,8 @@ function() { // Process pageviews after new are added document.addEventListener('eventAddedToMauticQueue', function(e) { - if(e.detail[0] == 'send' && e.detail[1] == 'pageview'){ - m.sendPageview(e.detail); + if (MauticJS.ensureEventContext(e, 'send', 'pageview')) { + m.sendPageview(e.detail); } }); })(MauticJS, location, navigator, document); From 292876af66187cd9e93ffa93c176b3863b336a0a Mon Sep 17 00:00:00 2001 From: Zdeno Kuzmany Date: Wed, 30 Jan 2019 23:47:31 +0100 Subject: [PATCH 3/3] Replace hasOwnProperty condition with type of --- app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php b/app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php index 1c45617db61..199fa690ef8 100644 --- a/app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php +++ b/app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php @@ -424,10 +424,10 @@ enumerable: false, } } -MauticJS.ensureEventContext = function(event, context0, context1) { // - return event.hasOwnProperty('detail') +MauticJS.ensureEventContext = function(event, context0, context1) { + return (typeof(event.detail) !== 'undefined' && event.detail[0] === context0 - && event.detail[1] === context1; + && event.detail[1] === context1); }; JS; $event->appendJs($js, 'Mautic Core');