]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6316 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 13 Nov 2023 15:59:56 +0000 (16:59 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 13 Nov 2023 15:59:56 +0000 (16:59 +0100)
app/Fluidbook/Compiler/Stats.php
app/Models/Traits/PublicationSettings.php

index 40903875cf0c7440d11e4d8851d79bf981c32aec..b75574e79ef9e7a93cb45bf0272ebcc2f4bd6c7a 100644 (file)
@@ -22,26 +22,8 @@ trait Stats
             $this->config->statsMatomo = false;
         }
 
-        if ($this->fluidbookSettings->tagcommander_id) {
-            $id = $this->fluidbookSettings->tagcommander_id;
-            if (!$this->fluidbookSettings->tagcommander_prod) {
-                $id .= '/uat';
-            }
-
-            $default = ['page_name' => ''];
-            $this->config->tagcommander_default_vars = array_merge($default, $this->parseVariables($this->fluidbookSettings->tagcommander_default_vars));
-            $this->config->set('tagcommander_default_vars.env_work', $this->fluidbookSettings->tagcommander_prod ? 'prod' : 'pre-prod');
+        $this->_tagCommander();
 
-            $scriptNames = explode(',', $this->config->tagcommander_scriptname);
-            $this->fluidbookSettings->googleAnalyticsCustom .= '<script>window.tc_vars=' . json_encode($this->config->tagcommander_default_vars) . ';</script><script src="//cdn.tagcommander.com/' . $id . '/' . $scriptNames[0] . '"></script>';
-            for ($i = 1; $i < count($scriptNames); $i++) {
-                $this->fluidbookSettings->statsCustom .= '<script src="//cdn.tagcommander.com/' . $id . '/' . $scriptNames[$i] . '"></script>';
-            }
-
-            if ($this->fluidbookSettings->tagcommander_plan) {
-                $this->config->tagcommander_plan = $this->_parsePlan($this->fluidbookSettings->tagcommander_plan);
-            }
-        }
         if (isset($this->fluidbookSettings->googleTagManager) && $this->fluidbookSettings->googleTagManager) {
             $this->fluidbookSettings->googleAnalyticsCustom .= "<!-- Google Tag Manager -->
 <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
@@ -56,6 +38,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
 height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
 <!-- End Google Tag Manager (noscript) -->';
         }
+
         if ($this->fluidbookSettings->xiti) {
             $this->fluidbookSettings->googleAnalyticsCustom .= $this->fluidbookSettings->xiti;
             if ($this->fluidbookSettings->piano_plan) {
@@ -64,6 +47,52 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
         }
     }
 
+    protected function _tagCommander()
+    {
+        if ($this->fluidbookSettings->tagcommander_plan_type === 'file') {
+            if ($this->fluidbookSettings->tagcommander_id) {
+                $id = $this->fluidbookSettings->tagcommander_id;
+                if (!$this->fluidbookSettings->tagcommander_prod) {
+                    $id .= '/uat';
+                }
+
+                $default = ['page_name' => ''];
+                $this->config->tagcommander_default_vars = array_merge($default, $this->parseVariables($this->fluidbookSettings->tagcommander_default_vars));
+                $this->config->set('tagcommander_default_vars.env_work', $this->fluidbookSettings->tagcommander_prod ? 'prod' : 'pre-prod');
+
+                $scriptNames = explode(',', $this->config->tagcommander_scriptname);
+
+
+                if ($this->fluidbookSettings->tagcommander_plan) {
+                    $this->config->tagcommander_plan = $this->_parsePlan($this->fluidbookSettings->tagcommander_plan);
+                }
+            }
+        } else if ($this->fluidbookSettings->tagcommander_plan_type === 'esm') {
+            $default = [
+                'env_ati_id' => 576078,
+                'page_name' => 'magazine',
+                'env_work' => $this->fluidbookSettings->tagcommander_prod ? 'prod' : 'pre-prod',
+                'page_level_name' => 'fluidbook',
+                'magazine_device' => $this->isMobileFirst() ? 'mobile' : 'desktop',
+            ];
+            $this->config->tagcommander_default_vars = array_merge($default, $this->parseVariables($this->fluidbookSettings->tagcommander_default_vars));
+            $id = 5040;
+            if (!$this->fluidbookSettings->tagcommander_prod) {
+                $id .= '/uat';
+            }
+            $scriptNames = ['tc_Multisite_Medias.js', 'tc_Multisite_Analytics.js'];
+            $this->addJsLib('esm', ['js/fluidbook/stats/fluidbook.stats.esm.js']);
+        }
+
+        if (isset($id)) {
+            $this->fluidbookSettings->googleAnalyticsCustom .= '<script>window.tc_vars=' . json_encode($this->config->tagcommander_default_vars) . ';</script><script src="//cdn.tagcommander.com/' . $id . '/' . $scriptNames[0] . '"></script>';
+            for ($i = 1; $i < count($scriptNames); $i++) {
+                $this->fluidbookSettings->statsCustom .= '<script src="//cdn.tagcommander.com/' . $id . '/' . $scriptNames[$i] . '"></script>';
+            }
+        }
+
+    }
+
     protected function _parsePlan($filename)
     {
         $planPath = $this->_wdirOrAbsolute($filename);
index b5101c7338b8e93ecbd8e0131934059bd3c4a104..bfed2f93a601244c65a50b918226fd0f787679c8 100644 (file)
@@ -2108,6 +2108,7 @@ trait PublicationSettings
         );
         $this->addSettingField('tagcommander_id', LongText::class, 'Tag commander ID', [
             'v2' => '{"type":"text","default":"","editable":true,"label":"Tag commander ID","grade":3}',
+            'when' => ['tagcommander_plan_type' => 'file'],
         ]);
         $this->addSettingField('tagcommander_scriptname', LongText::class, 'Nom du script Tagcommander', [
             'v2' => '{"type":"text","default":"tc_Multisite_Head.js,tc_Multisite_Analytics.js,tc_Multisite_Medias.js","editable":true,"label":"Nom du script Tagcommander","grade":3}',