File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
Controller/Adminhtml/Container Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,7 @@ public function execute()
124124 'rm ' => true
125125 ];
126126 $ this ->fileFactory ->create (
127- sprintf ($ this -> config -> getPublicId () . '_%s.json ' , $ this ->dateTime ->date ('Y-m-d_H-i-s ' )),
127+ sprintf (' GTM ' . '_%s.json ' , $ this ->dateTime ->date ('Y-m-d_H-i-s ' )),
128128 $ fileContent ,
129129 DirectoryList::MEDIA ,
130130 'application/json '
Original file line number Diff line number Diff line change @@ -72,10 +72,7 @@ public function __construct(
7272 */
7373 public function isEnabled (string $ storeId = null ): bool
7474 {
75- return (bool )$ this ->getConfig (self ::XML_PATH_EXTENSION_ENABLED , $ storeId ) && (
76- ($ this ->getPublicId ($ storeId ) && 'use_public_id ' === $ this ->getInstallGtm ($ storeId ))
77- || ($ this ->getGtmScript ($ storeId ) && 'use_head_and_body_script ' === $ this ->getInstallGtm ($ storeId ))
78- );
75+ return (bool )$ this ->getConfig (self ::XML_PATH_EXTENSION_ENABLED , $ storeId );
7976 }
8077
8178 /**
@@ -117,7 +114,21 @@ public function getContainerId(string $storeId = null): string
117114 */
118115 public function getPublicId (string $ storeId = null ): string
119116 {
120- return trim ((string )$ this ->getConfig (self ::XML_PATH_WEB_PUBLIC_ID , $ storeId ));
117+ $ result = trim ((string )$ this ->getConfig (self ::XML_PATH_WEB_PUBLIC_ID , $ storeId ));
118+
119+ if (!$ result ) {
120+ if ($ gtmScript = $ this ->getGtmScript ($ storeId )) {
121+ $ pattern = '/GTM-[A-Z0-9]+/ ' ;
122+ $ matches = [];
123+ if (preg_match ($ pattern , $ gtmScript , $ matches )) {
124+ if (isset ($ matches [0 ])) {
125+ return (string )$ matches [0 ];
126+ }
127+ }
128+ }
129+ }
130+
131+ return $ result ;
121132 }
122133
123134 /**
You can’t perform that action at this time.
0 commit comments