Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Analytics Advertising Features #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions MarkupSEO.module
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
public static function getModuleInfo() {
return array(
'title' => __('SEO'),
'version' => '0.8.7',
'version' => '0.8.9',
'summary' => __('The all-in-one SEO solution for ProcessWire.'),
'autoload' => true,
'requires' => array('ProcessWire>=2.4.0', 'PHP>=5.3.8')
Expand Down Expand Up @@ -51,6 +51,7 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
'includeTemplates' => array(),
'usePermission' => 0,
'googleAnalytics' => '',
'googleAnalyticsAdvertisingFeatures' => false,
'googleAnalyticsAnonymizeIP' => false,
'piwikAnalyticsUrl' => '',
'piwikAnalyticsIDSite' => '',
Expand Down Expand Up @@ -273,19 +274,35 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {

// add opengraph and canonical
if(!$pageData['canonical']) {

if($configData['canonicalProtocol'] == 'auto') {
if(wire('config')->https == true) $configData['canonicalProtocol'] = 'https';
}

foreach(wire('languages') as $language) {
if(!$page->viewable($language)) continue;
$hreflang = $language->name;
if ($hreflang != "default") $urlLanguague[$hreflang] = $page->localHttpUrl($language);
}

if($configData['canonicalProtocol'] == 'https') {
$pageData['canonical'] = preg_replace('%^https?%i', 'https', $page->httpUrl);
if (!empty($urlLanguague)) {
foreach($urlLanguague as $key => $urlLang) {
$pageData['hreflang'][$key] = preg_replace('%^https?%i', 'https', $urlLang);
}
}
} else {
$pageData['canonical'] = $page->httpUrl;
if (!empty($urlLanguague)) {
foreach($urlLanguague as $key => $urlLang) {
$pageData['hreflang'][$key] = $urlLang;
}
}
}

}


if($configData['includeOpenGraph']) {
$pageData['og:site_name'] = $configData['sitename'];
$pageData['og:title'] = $pageData['title'];
Expand Down Expand Up @@ -326,18 +343,24 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');

ga(\'create\', \''.$configData['googleAnalytics'].'\', \'auto\');
';

// The display features plugin for analytics.js can be used to enable Advertising Features in Google Analytics, such as Remarketing, Demographics and Interest Reporting, and more.
if( $configData['googleAnalyticsAdvertisingFeatures'] ) {
$googleAnalytics .= '
ga(\'require\', \'displayfeatures\');
ga(\'require\', \'linkid\', \'linkid.js\');'."\n";
}

// Add "anonymizeIp" option if activated
if( $configData['googleAnalyticsAnonymizeIP'] ) {
$googleAnalytics .= 'ga(\'set\', \'anonymizeIp\', true)';
$googleAnalytics .= 'ga(\'set\', \'anonymizeIp\', true);'."\n";
}
$googleAnalytics .= ';
ga(\'send\', \'pageview\');


$googleAnalytics .= 'ga(\'send\', \'pageview\');
</script>
<!-- End: Google Analytics -->';
<!-- End: Google Analytics -->'."\n";
}

$piwikAnalytics = '';
Expand Down Expand Up @@ -371,6 +394,13 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
case 'canonical':
$rendered .= '<link rel="canonical" href="'.$content.'" />'.PHP_EOL;
break;
case 'hreflang':
foreach($content as $hreflang => $url)
$rendered .= '<link rel="alternate" hreflang="'.$hreflang.'" href="'.$url.'" />'.PHP_EOL;
break;
case 'http-equiv':
$rendered .= '<meta http-equiv="refresh" content="'.$content.'" />'.PHP_EOL;
break;
default:
if (strstr($name, 'og:')) {
$rendered .= '<meta property="'.$name.'" content="'.$content.'" />'.PHP_EOL;
Expand Down Expand Up @@ -801,7 +831,7 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
$field->description = __("Google Analytics code will be embedded if this field is populated.");
$field->notes = __('How to find your code: https://support.google.com/analytics/answer/1008080. It should look like: UA-XXXXXXX-X.');
$field->value = $data['googleAnalytics'];
$field->columnWidth = '50%';
$field->columnWidth = '34%';
$fieldset->add($field);

// Anonymize IP
Expand All @@ -810,7 +840,16 @@ class MarkupSEO extends WireData implements Module, ConfigurableModule {
$field->label = __("Google Analytics: Anonymize IPs?");
$field->description = __('In some countrys (like Germany) anonymizing the visitors IP in Google Analytics is an obligatory setting for legal reasons.');
$field->checked = $data['googleAnalyticsAnonymizeIP'];
$field->columnWidth = '50%';
$field->columnWidth = '33%';
$fieldset->add($field);

// Advertising Features
$field = $modules->get("InputfieldCheckbox");
$field->name = "googleAnalyticsAdvertisingFeatures";
$field->label = __("Google Analytics: Advertising Features?");
$field->description = __('The display features plugin for analytics.js can be used to enable Advertising Features in Google Analytics, such as Remarketing, Demographics and Interest Reporting, and more.');
$field->checked = $data['googleAnalyticsAdvertisingFeatures'];
$field->columnWidth = '33%';
$fieldset->add($field);


Expand Down