diff --git a/readme.txt b/readme.txt index aa59dea..611a4b4 100644 --- a/readme.txt +++ b/readme.txt @@ -97,6 +97,7 @@ Find out about what's new in our [our release post](https://gtmkit.com/gtm-kit-1 #### Enhancements: - Added advanced GCM settings: 'ads_data_redaction', 'url_passthrough' and 'wait_for_update'. +- Updated the custom container loader. #### Bugfixes: diff --git a/src/Frontend/Frontend.php b/src/Frontend/Frontend.php index 1752378..2e7282a 100644 --- a/src/Frontend/Frontend.php +++ b/src/Frontend/Frontend.php @@ -209,15 +209,16 @@ public function get_gtm_script( string $gtm_id ): void { $loader = $this->options->get( 'general', 'sgtm_container_identifier' ) ? $this->options->get( 'general', 'sgtm_container_identifier' ) : 'gtm'; if ( $this->options->get( 'general', 'sgtm_cookie_keeper' ) ) { + $gtm_id = preg_replace( '/^GTM\-/i', '', $gtm_id ); echo "/* Google Tag Manager with Stape.io Cookie Keeper */\n"; - echo '!function(){"use strict";function e(e,t,o){return void 0===t&&(t=""),"cookie"===e?function(e){for(var t=0,o=document.cookie.split(";");t=16.4)?e(l,"_sbp",""):void 0}catch(e){console.error(e)}var g=t;g[n]=g[n]||[];g[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var m=o.getElementsByTagName(r)[0],T=v?"&bi="+encodeURIComponent(v):"",_=o.createElement(r),f=v?"kp"+c:c,dl=n!="dataLayer"?"&l="+n:"";_.async=!0,_.src="https://' . esc_attr( $domain ) . '/"+f+".js?id=' . esc_attr( $gtm_id ) . '"+dl+T' . ( ( ! empty( Options::init()->get( 'general', 'gtm_auth' ) ) && ! empty( Options::init()->get( 'general', 'gtm_preview' ) ) ) ? "+'>m_auth=" . esc_attr( Options::init()->get( 'general', 'gtm_auth' ) ) . '>m_preview=' . esc_attr( Options::init()->get( 'general', 'gtm_preview' ) ) . ">m_cookies_win=x'" : '' ) . ',null===(d=m.parentNode)||void 0===d||d.insertBefore(_,m)}(window,document,"script","' . esc_js( $this->datalayer_name ) . '",0,0,"' . esc_attr( $loader ) . '","cookie")}();'; + echo '!function(){"use strict";function l(e){for(var t=e,r=0,n=document.cookie.split(";");rdatalayer_name ) . '",o="' . esc_js( $gtm_id ) . '",a="https://' . esc_attr( $domain ) . '",i="",c="' . esc_attr( $loader ) . '",E="cookie",I="_sbp",v="",g=!1;try{var g=!!E&&(m=navigator.userAgent,!!(m=new RegExp("Version/([0-9._]+)(.*Mobile)?.*Safari.*").exec(m)))&&16.4<=parseFloat(m[1]),A="stapeUserId"===E,f=g&&!A?function(e,t,r){void 0===t&&(t="");var n={cookie:l,localStorage:s,jsVariable:u,cssSelector:d},t=Array.isArray(t)?t:[t];if(e&&n[e])for(var o=n[e],a=0,i=t;aget( 'general', 'gtm_auth' ) ) && ! empty( Options::init()->get( 'general', 'gtm_preview' ) ) ) ? "+'>m_auth=" . esc_attr( Options::init()->get( 'general', 'gtm_auth' ) ) . '>m_preview=' . esc_attr( Options::init()->get( 'general', 'gtm_preview' ) ) . ">m_cookies_win=x'" : '' ) . ',null!=(f=E.parentNode)&&f.insertBefore(A,E)}();'; echo "\n/* End Google Tag Manager */\n"; } else { echo "/* Google Tag Manager */\n"; echo "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n"; echo "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n"; echo "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n"; - echo "'https://" . esc_attr( $domain ) . '/' . esc_attr( $loader ) . ".js?id='+i+dl"; + echo "'https://" . esc_attr( $domain ) . '/' . esc_attr( $loader ) . '.js?' . ( $loader === 'gtm' ) ? 'id' : 'st' . "='+i+dl"; echo ( ! empty( $this->options->get( 'general', 'gtm_auth' ) ) && ! empty( $this->options->get( 'general', 'gtm_preview' ) ) ) ? "+'>m_auth=" . esc_attr( $this->options->get( 'general', 'gtm_auth' ) ) . '>m_preview=' . esc_attr( $this->options->get( 'general', 'gtm_preview' ) ) . ">m_cookies_win=x'" : ''; echo ";f.parentNode.insertBefore(j,f);\n"; echo "})(window,document,'script','" . esc_js( $this->datalayer_name ) . "','" . esc_attr( $gtm_id ) . "');\n";