Update plugin.php

Site verification and tag insertion fixed. Code cleaning.
This commit is contained in:
Max Kostikov 2017-11-21 19:59:43 +02:00 committed by GitHub
parent c6496250dd
commit acfe7a03a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 73 additions and 74 deletions

View File

@ -5,8 +5,8 @@ class pluginGoogle extends Plugin {
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'google-analytics-tracking-id'=>'',
'google-site-verification'=>'', 'google-site-verification'=>'',
'google-analytics-tracking-id'=>'',
'google-tag-manager'=>'' 'google-tag-manager'=>''
); );
} }
@ -16,20 +16,20 @@ class pluginGoogle extends Plugin {
global $Language; global $Language;
$html = '<div>'; $html = '<div>';
$html .= '<label for="jsgoogle-site-verification">'.$Language->get('Google Webmasters tools').'</label>'; $html .= '<label>'.$Language->get('Google Webmasters tools').'</label>';
$html .= '<input id="jsgoogle-site-verification" type="text" name="google-site-verification" value="'.$this->getDbField('google-site-verification').'">'; $html .= '<input type="text" name="google-site-verification" value="'.$this->getDbField('google-site-verification').'">';
$html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-google-site-verification').'</span>'; $html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-google-site-verification').'</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label for="jstracking-id">'.$Language->get('Google Analytics Tracking ID').'</label>'; $html .= '<label>'.$Language->get('Google Analytics Tracking ID').'</label>';
$html .= '<input id="jsgoogle-analytics-tracking-id" type="text" name="google-analytics-tracking-id" value="'.$this->getDbField('google-analytics-tracking-id').'">'; $html .= '<input type="text" name="google-analytics-tracking-id" value="'.$this->getDbField('google-analytics-tracking-id').'">';
$html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-tracking-id').'</span>'; $html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-tracking-id').'</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label for="jsgoogle-tag-manager">'.$Language->get('Google Tag Manager').'</label>'; $html .= '<label>'.$Language->get('Google Tag Manager').'</label>';
$html .= '<input id="jsgoogle-tag-manager" type="text" name="google-tag-manager" value="'.$this->getDbField('google-tag-manager').'">'; $html .= '<input type="text" name="google-tag-manager" value="'.$this->getDbField('google-tag-manager').'">';
$html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-tracking-id-google-tag').'</span>'; $html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-tracking-id-google-tag').'</span>';
$html .= '</div>'; $html .= '</div>';
@ -39,19 +39,18 @@ class pluginGoogle extends Plugin {
public function siteHead() public function siteHead()
{ {
global $Url; global $Url;
global $WHERE_AM_I;
$html = ''; $html = "";
// Google HTML tag // Google HTML tag
if ($this->getValue('google-site-verification') && ($WHERE_AM_I=='home')) { if( $this->getValue('google-site-verification') && $Url->whereAmI()=='home' ) {
$html .= PHP_EOL.'<!-- Google HTML tag -->'.PHP_EOL; $html .= PHP_EOL."<!-- Google HTML tag -->";
$html .= '<meta name="google-site-verification" content="'.$this->getDbField('google-site-verification').'" />'.PHP_EOL; $html .= '<meta name="google-site-verification" content="'.$this->getDbField('google-site-verification').'" />'.PHP_EOL;
} }
// Google Tag Manager // Google Tag Manager
if( $this->getValue('google-tag-manager') ) { if( $this->getValue('google-tag-manager') ) {
$html .= PHP_EOL."<!-- Google Tag Manager -->".PHP_EOL; $html .= PHP_EOL."<!-- Google Tag Manager -->";
$html .= "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':".PHP_EOL; $html .= "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':".PHP_EOL;
$html .= "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],".PHP_EOL; $html .= "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],".PHP_EOL;
$html .= "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=".PHP_EOL; $html .= "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=".PHP_EOL;
@ -62,7 +61,7 @@ class pluginGoogle extends Plugin {
// Google Analytics // Google Analytics
if( $this->getValue('google-analytics-tracking-id') ) { if( $this->getValue('google-analytics-tracking-id') ) {
$html = PHP_EOL.'<!-- Google Analytics -->'.PHP_EOL; $html .= PHP_EOL."<!-- Google Analytics -->";
$html .= ' $html .= '
<script async src="https://www.googletagmanager.com/gtag/js?id='.$this->getValue('google-analytics-tracking-id').'"></script> <script async src="https://www.googletagmanager.com/gtag/js?id='.$this->getValue('google-analytics-tracking-id').'"></script>
<script> <script>
@ -81,7 +80,7 @@ class pluginGoogle extends Plugin {
{ {
// Google Tag Manager // Google Tag Manager
if ($this->getValue('google-tag-manager')) { if ($this->getValue('google-tag-manager')) {
$html = '<!-- Google Tag Manager (noscript) -->'.PHP_EOL; $html = '<!-- Google Tag Manager (noscript) -->';
$html .= '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id='.$this->getValue('google-tag-manager').'" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>'.PHP_EOL; $html .= '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id='.$this->getValue('google-tag-manager').'" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>'.PHP_EOL;
$html .= '<!-- End Google Tag Manager (noscript) -->'.PHP_EOL; $html .= '<!-- End Google Tag Manager (noscript) -->'.PHP_EOL;
return $html; return $html;