From c7e1efd67a4be1d8e3d8628c5a4730e0ee1fa17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20HULARD?= Date: Tue, 18 Feb 2020 10:40:03 +0100 Subject: [PATCH 1/4] Add a new function `wpmautic_base_script` Since we'll allow to not load the tracking script when rendering the page we must allow users to retrieve the script URL to load it by themselves if they need to. --- wpmautic.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/wpmautic.php b/wpmautic.php index 072d7e5..df7ef0d 100644 --- a/wpmautic.php +++ b/wpmautic.php @@ -120,13 +120,28 @@ function wpmautic_injector() { } } +/** + * Generate the mautic script URL to be used outside of the plugin when + * necessary + * + * @return string + */ +function wpmautic_base_script() { + $base_url = wpmautic_option( 'base_url', '' ); + if ( empty( $base_url ) ) { + return; + } + + return $base_url . '/mtc.js'; +} + /** * Writes Tracking JS to the HTML source * * @return void */ function wpmautic_inject_script() { - $base_url = wpmautic_option( 'base_url', '' ); + $base_url = wpmautic_base_script(); if ( empty( $base_url ) ) { return; } @@ -137,7 +152,7 @@ function wpmautic_inject_script() { (function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n; w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t), m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m) - })(window,document,'script','/mtc.js','mt'); + })(window,document,'script','','mt'); mt('send', 'pageview' 0 ? ', ' . wp_json_encode( $attrs ) : ''; ?>); From 6515cee3a1998f77d478aac5fb3f78e36286cd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20HULARD?= Date: Tue, 18 Feb 2020 10:41:03 +0100 Subject: [PATCH 2/4] Script location: Add a new value - disabled. This new value will tell the plugin to not load the tracking script in the page by default, hello GDPR ^^. --- options.php | 17 +++++++++++++++-- tests/OptionsTest.php | 8 ++++++++ tests/OptionsValidationTest.php | 16 ++++++++++++++++ tests/ScriptInjectionTest.php | 18 ++++++++++++++++++ tests/SettingsTest.php | 13 +++++++++++++ wpmautic.php | 4 ++-- 6 files changed, 72 insertions(+), 4 deletions(-) diff --git a/options.php b/options.php index f467228..ebbd0c3 100644 --- a/options.php +++ b/options.php @@ -132,13 +132,26 @@ function wpmautic_script_location() { ?>
+ +