Skip to content
Snippets Groups Projects
Commit 15f09733 authored by Michael Lee's avatar Michael Lee
Browse files

Upgrading drupal/google_analytics (2.5.0 => 4.0.0)

parent 51f51738
No related branches found
No related tags found
No related merge requests found
Showing
with 388 additions and 571 deletions
......@@ -3,7 +3,8 @@
"description": "OSU ASC Pantheon custom upstream for Drupal 8",
"type": "project",
"license": "None",
"repositories": [{
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
......@@ -121,7 +122,7 @@
"drupal/field_permissions": "1.1",
"drupal/file_browser": "1.3",
"drupal/focal_point": "1.5",
"drupal/google_analytics": "2.5",
"drupal/google_analytics": "^4.0",
"drupal/google_tag": "1.4",
"drupal/honeypot": "2.0.1",
"drupal/inline_entity_form": "1.0-rc9",
......@@ -225,12 +226,27 @@
},
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/libraries/{$name}": ["type:drupal-library", "enyo/dropzone", "desandro/masonry", "dimsemenov/magnific-popup"],
"web/modules/{$name}": ["type:drupal-module"],
"web/profiles/contrib/{$name}": ["type:drupal-profile"],
"web/themes/{$name}": ["type:drupal-theme"],
"drush/contrib/{$name}": ["type:drupal-drush"]
"web/core": [
"type:drupal-core"
],
"web/libraries/{$name}": [
"type:drupal-library",
"enyo/dropzone",
"desandro/masonry",
"dimsemenov/magnific-popup"
],
"web/modules/{$name}": [
"type:drupal-module"
],
"web/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"web/themes/{$name}": [
"type:drupal-theme"
],
"drush/contrib/{$name}": [
"type:drupal-drush"
]
},
"build-env": {
"install-cms": [
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "09537e7c3c425c2a37646d9578cdef43",
"content-hash": "ddbb6bfcc5492e80908375b84ecb45bb",
"packages": [
{
"name": "alchemy/zippy",
......@@ -4502,20 +4502,20 @@
},
{
"name": "drupal/google_analytics",
"version": "2.5.0",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/google_analytics.git",
"reference": "8.x-2.5"
"reference": "4.0.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/google_analytics-8.x-2.5.zip",
"reference": "8.x-2.5",
"shasum": "9e0ff72cc313bf9295fe8bd73a68f5f7688513ab"
"url": "https://ftp.drupal.org/files/projects/google_analytics-4.0.0.zip",
"reference": "4.0.0",
"shasum": "4f761d4c852d11966f7289b0eb6431cc8db27240"
},
"require": {
"drupal/core": "^8.8.6|^9.0"
"drupal/core": "^8.9|^9.0"
},
"require-dev": {
"drupal/token": "^1.7"
......@@ -4523,15 +4523,15 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-2.5",
"datestamp": "1591298527",
"version": "4.0.0",
"datestamp": "1634230238",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
},
"branch-alias": {
"dev-8.x-2.x": "2.x-dev"
"dev-4.x": "4.x-dev"
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
......@@ -4567,7 +4567,7 @@
"description": "Allows your site to be tracked by Google Analytics by adding a Javascript tracking code to every page.",
"homepage": "https://www.drupal.org/project/google_analytics",
"support": {
"source": "https://git.drupal.org/project/google_analytics.git",
"source": "https://git.drupalcode.org/project/google_analytics",
"issues": "https://www.drupal.org/project/issues/google_analytics"
}
},
......@@ -13241,16 +13241,16 @@
},
{
"name": "symfony/finder",
"version": "v4.4.37",
"version": "v4.4.41",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "b17d76d7ed179f017aad646e858c90a2771af15d"
"reference": "40790bdf293b462798882ef6da72bb49a4a6633a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/b17d76d7ed179f017aad646e858c90a2771af15d",
"reference": "b17d76d7ed179f017aad646e858c90a2771af15d",
"url": "https://api.github.com/repos/symfony/finder/zipball/40790bdf293b462798882ef6da72bb49a4a6633a",
"reference": "40790bdf293b462798882ef6da72bb49a4a6633a",
"shasum": ""
},
"require": {
......@@ -13283,7 +13283,7 @@
"description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/finder/tree/v4.4.37"
"source": "https://github.com/symfony/finder/tree/v4.4.41"
},
"funding": [
{
......@@ -13299,7 +13299,7 @@
"type": "tidelift"
}
],
"time": "2022-01-02T09:41:36+00:00"
"time": "2022-04-14T15:36:10+00:00"
},
{
"name": "symfony/http-client-contracts",
......
......@@ -4647,21 +4647,21 @@
},
{
"name": "drupal/google_analytics",
"version": "2.5.0",
"version_normalized": "2.5.0.0",
"version": "4.0.0",
"version_normalized": "4.0.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/google_analytics.git",
"reference": "8.x-2.5"
"reference": "4.0.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/google_analytics-8.x-2.5.zip",
"reference": "8.x-2.5",
"shasum": "9e0ff72cc313bf9295fe8bd73a68f5f7688513ab"
"url": "https://ftp.drupal.org/files/projects/google_analytics-4.0.0.zip",
"reference": "4.0.0",
"shasum": "4f761d4c852d11966f7289b0eb6431cc8db27240"
},
"require": {
"drupal/core": "^8.8.6|^9.0"
"drupal/core": "^8.9|^9.0"
},
"require-dev": {
"drupal/token": "^1.7"
......@@ -4669,15 +4669,15 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-2.5",
"datestamp": "1591298527",
"version": "4.0.0",
"datestamp": "1634230238",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
},
"branch-alias": {
"dev-8.x-2.x": "2.x-dev"
"dev-4.x": "4.x-dev"
}
},
"installation-source": "dist",
......@@ -4714,7 +4714,7 @@
"description": "Allows your site to be tracked by Google Analytics by adding a Javascript tracking code to every page.",
"homepage": "https://www.drupal.org/project/google_analytics",
"support": {
"source": "https://git.drupal.org/project/google_analytics.git",
"source": "https://git.drupalcode.org/project/google_analytics",
"issues": "https://www.drupal.org/project/issues/google_analytics"
},
"install-path": "../../web/modules/google_analytics"
......@@ -13623,24 +13623,24 @@
},
{
"name": "symfony/finder",
"version": "v4.4.37",
"version_normalized": "4.4.37.0",
"version": "v4.4.41",
"version_normalized": "4.4.41.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "b17d76d7ed179f017aad646e858c90a2771af15d"
"reference": "40790bdf293b462798882ef6da72bb49a4a6633a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/b17d76d7ed179f017aad646e858c90a2771af15d",
"reference": "b17d76d7ed179f017aad646e858c90a2771af15d",
"url": "https://api.github.com/repos/symfony/finder/zipball/40790bdf293b462798882ef6da72bb49a4a6633a",
"reference": "40790bdf293b462798882ef6da72bb49a4a6633a",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"symfony/polyfill-php80": "^1.16"
},
"time": "2022-01-02T09:41:36+00:00",
"time": "2022-04-14T15:36:10+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
......@@ -13668,7 +13668,7 @@
"description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/finder/tree/v4.4.37"
"source": "https://github.com/symfony/finder/tree/v4.4.41"
},
"funding": [
{
......
......@@ -5,7 +5,7 @@
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '002a337b01d47db573b437ed8bdc143bf2bb617b',
'reference' => '51f5173881510201397d977bee2cd820809999e7',
'name' => 'osu-asc-webservices/d8-upstream',
'dev' => true,
),
......@@ -1016,12 +1016,12 @@
),
),
'drupal/google_analytics' => array(
'pretty_version' => '2.5.0',
'version' => '2.5.0.0',
'pretty_version' => '4.0.0',
'version' => '4.0.0.0',
'type' => 'drupal-module',
'install_path' => __DIR__ . '/../../web/modules/google_analytics',
'aliases' => array(),
'reference' => '8.x-2.5',
'reference' => '4.0.0',
'dev_requirement' => false,
),
'drupal/google_tag' => array(
......@@ -2101,7 +2101,7 @@
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '002a337b01d47db573b437ed8bdc143bf2bb617b',
'reference' => '51f5173881510201397d977bee2cd820809999e7',
'dev_requirement' => false,
),
'pantheon-systems/quicksilver-pushback' => array(
......@@ -2709,12 +2709,12 @@
'dev_requirement' => false,
),
'symfony/finder' => array(
'pretty_version' => 'v4.4.37',
'version' => '4.4.37.0',
'pretty_version' => 'v4.4.41',
'version' => '4.4.41.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/finder',
'aliases' => array(),
'reference' => 'b17d76d7ed179f017aad646e858c90a2771af15d',
'reference' => '40790bdf293b462798882ef6da72bb49a4a6633a',
'dev_requirement' => false,
),
'symfony/http-client-contracts' => array(
......
......@@ -83,7 +83,13 @@ protected function isAccepted($string)
*/
protected function isRegex($str)
{
if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
$availableModifiers = 'imsxuADU';
if (\PHP_VERSION_ID >= 80200) {
$availableModifiers .= 'n';
}
if (preg_match('/^(.{3,}?)['.$availableModifiers.']*$/', $str, $m)) {
$start = substr($m[1], 0, 1);
$end = substr($m[1], -1);
......
{
"globals": {
"ga": true
"gtag": true
}
}
......@@ -77,7 +77,7 @@ One example for custom dimensions tracking is the "User roles" tracking.
e.g. "User roles". This step is required. Do not miss it, please.
2. Enter the below configuration data into the Drupal custom dimensions
settings form under admin/config/system/googleanalytics. You can also
settings form under admin/config/services/googleanalytics. You can also
choose another index, but keep it always in sync with the index used in
step #1.
......@@ -111,6 +111,7 @@ Body:
```
<ul>
<li><a href="mailto:foo@example.com">Mailto</a></li>
<li><a href="tel:+1-303-499-7111">Tel</a></li>
<li><a href="/files/test.txt">Download file</a></li>
<li><a class="colorbox" href="#">Open colorbox</a></li>
<li><a href="https://example.com/">External link</a></li>
......
......@@ -11,18 +11,18 @@
],
"support": {
"issues": "https://www.drupal.org/project/issues/google_analytics",
"source": "https://git.drupal.org/project/google_analytics.git"
"source": "https://git.drupalcode.org/project/google_analytics"
},
"license": "GPL-2.0-or-later",
"require": {
"drupal/core": "^8.8.6|^9.0"
"drupal/core": "^8.9|^9.0"
},
"require-dev": {
"drupal/token": "^1.7"
},
"extra": {
"branch-alias": {
"dev-8.x-2.x": "2.x-dev"
"dev-4.x": "4.x-dev"
}
}
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ visibility:
track:
outbound: true
mailto: true
tel: true
files: true
files_extensions: '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc(x|m)?|dot(x|m)?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt(x|m)?|pot(x|m)?|pps(x|m)?|ppam|sld(x|m)?|thmx|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls(x|m|b)?|xlt(x|m)|xlam|xml|z|zip'
colorbox: true
......@@ -20,12 +21,11 @@ track:
messages: { }
site_search: false
adsense: false
displayfeatures: false
displayfeatures: true
privacy:
anonymizeip: true
custom:
dimension: { }
metric: { }
parameters: { }
codesnippet:
create: { }
before: ''
......
......@@ -48,6 +48,9 @@ google_analytics.settings:
mailto:
type: boolean
label: 'Track clicks on mailto links'
tel:
type: boolean
label: 'Track clicks on tel links'
files:
type: boolean
label: 'Track downloads'
......@@ -92,29 +95,19 @@ google_analytics.settings:
type: mapping
label: 'Custom variables'
mapping:
dimension:
parameters:
type: sequence
label: 'Custom dimensions'
label: 'Custom Parameters'
sequence:
type: mapping
label: 'Dimension'
label: 'Parameter'
mapping:
index:
type: integer
label: Index
value:
type:
type: string
label: Value
metric:
type: sequence
label: 'Custom metrics'
sequence:
type: mapping
label: 'Metric'
mapping:
index:
type: integer
label: Index
label: type
name:
type: string
label: Name
value:
type: string
label: Value
......@@ -124,10 +117,10 @@ google_analytics.settings:
mapping:
create:
type: sequence
label: 'Create only fields'
label: 'Parameters'
sequence:
type: ignore
label: 'Create field'
label: 'Parameter'
before:
type: string
label: 'Code snippet (before)'
......
......@@ -2,10 +2,10 @@ name: 'Google Analytics'
type: module
description: 'Allows your site to be tracked by Google Analytics by adding a Javascript tracking code to every page.'
package: Statistics
core_version_requirement: ^8.8.6 || ^9
core_version_requirement: ^8.9 || ^9
configure: google_analytics.admin_settings_form
# Information added by Drupal.org packaging script on 2020-06-04
version: '8.x-2.5'
# Information added by Drupal.org packaging script on 2021-10-14
version: '4.0.0'
project: 'google_analytics'
datestamp: 1591298498
datestamp: 1634230241
......@@ -28,7 +28,8 @@ function google_analytics_install() {
* Remove cache directory if module is uninstalled.
*/
function google_analytics_uninstall() {
google_analytics_clear_js_cache();
$javascript_service = \Drupal::service('google_analytics.javascript_cache');
$javascript_service->clearGoogleAnalyticsJsCache();
}
/**
......@@ -39,9 +40,10 @@ function google_analytics_requirements($phase) {
if ($phase == 'runtime') {
$config = \Drupal::config('google_analytics.settings');
$ga_accounts = \Drupal::service('google_analytics.accounts');
// Raise warning if Google user account has not been set yet.
if (!preg_match('/^UA-\d+-\d+$/', $config->get('account'))) {
if (!$ga_accounts->getDefaultMeasurementId()) {
$requirements['google_analytics_account'] = [
'title' => t('Google Analytics module'),
'description' => t('Google Analytics module has not been configured yet. Please configure its settings from the <a href=":url">Google Analytics settings page</a>.', [':url' => Url::fromRoute('google_analytics.admin_settings_form')->toString()]),
......@@ -72,3 +74,76 @@ function google_analytics_requirements($phase) {
return $requirements;
}
/**
* Migrate create only fields to gtag.js parameters.
*/
function google_analytics_update_8300() {
$config = \Drupal::configFactory()->getEditable('google_analytics.settings');
$create_only_fields = $config->get('codesnippet.create');
$parameters = [
'client_id' => $create_only_fields['clientId'],
'cookie_name' => $create_only_fields['cookieName'],
'cookie_domain' => $create_only_fields['cookieDomain'],
'cookie_expires' => $create_only_fields['cookieExpires'],
'sample_rate' => $create_only_fields['sampleRate'],
'site_speed_sample_rate' => $create_only_fields['siteSpeedSampleRate'],
'use_amp_client_id' => $create_only_fields['useAmpClientId'],
'user_id' => $create_only_fields['userId'],
];
$parameters = array_filter($parameters);
$config
->set('codesnippet.create', $parameters)
->save();
return t('Migrated create only fields to gtag.js parameters.');
}
/**
* Set default config for tel: link tracking.
*/
function google_analytics_update_8301() {
\Drupal::configFactory()
->getEditable('google_analytics.settings')
->set('track.tel', TRUE)
->save();
}
/**
* Update existing custom dimensions and metrics to user parameters.
*/
function google_analytics_update_8400() {
$config = \Drupal::configFactory()->getEditable('google_analytics.settings');
$custom_parameters = [];
$custom_dimensions = $config->getOriginal('custom.dimension');
$custom_metrics = $config->getOriginal('custom.metric');
// Merge Dimensions
if (!empty($custom_dimensions)) {
foreach ($custom_dimensions as $key => $dimension) {
$custom_parameters['dimension' . $key]['type'] = 'dimension';
$custom_parameters['dimension' . $key]['name'] = $dimension['name'];
$custom_parameters['dimension' . $key]['value'] = $dimension['value'];
}
}
// Merge Metrics
if (!empty($custom_metrics)) {
foreach ($custom_metrics as $key => $metric) {
$custom_parameters['metric' . $key]['type'] = 'metric';
$custom_parameters['metric' . $key]['name'] = $metric['name'];
$custom_parameters['metric' . $key]['value'] = $metric['value'];
}
}
if (!empty($custom_parameters)) {
$config->set('custom.parameters', $custom_parameters);
}
// Remove the legacy settings.
$config->clear('custom.metric');
$config->clear('custom.dimension');
// Save the settings
$config->save();
}
\ No newline at end of file
google_analytics.admin_settings_form:
title: 'Google Analytics'
parent: system.admin_config_system
parent: system.admin_config_services
description: 'Configure tracking behavior to get insights into your website traffic and marketing effectiveness.'
route_name: google_analytics.admin_settings_form
This diff is collapsed.
google_analytics.admin_settings_form:
path: '/admin/config/system/google-analytics'
path: '/admin/config/services/google-analytics'
defaults:
_form: '\Drupal\google_analytics\Form\GoogleAnalyticsAdminSettingsForm'
_title: 'Google Analytics'
......
services:
google_analytics.visibility:
class: Drupal\google_analytics\Helpers\VisiblityTracker
arguments: [ '@config.factory', '@path_alias.manager', '@path.matcher', '@user.data', '@path.current' ]
google_analytics.accounts:
class: Drupal\google_analytics\Helpers\GoogleAnalyticsAccounts
arguments: [ '@config.factory', '@private_key' ]
google_analytics.javascript_cache:
class: Drupal\google_analytics\JavascriptLocalCache
arguments: [ '@http_client', '@file_system', '@config.factory', '@logger.factory', '@state' ]
# Google Analytics Event Subscribers
google_analytics.events.messages:
class: '\Drupal\google_analytics\EventSubscriber\GoogleAnalyticsEvents\DrupalMessage'
arguments: [ '@config.factory', '@google_analytics.accounts', '@messenger' ]
tags:
- { name: 'event_subscriber' }
google_analytics.pagepath.content_translation:
class: '\Drupal\google_analytics\EventSubscriber\PagePath\ContentTranslation'
arguments: [ '@config.factory', '@request_stack', '@module_handler', '@entity.repository' ]
tags:
- { name: 'event_subscriber' }
google_analytics.pagepath.http_status:
class: '\Drupal\google_analytics\EventSubscriber\PagePath\HttpStatus'
arguments: [ '@config.factory', '@request_stack' ]
tags:
- { name: 'event_subscriber' }
google_analytics.pagepath.invalid_user_login:
class: '\Drupal\google_analytics\EventSubscriber\PagePath\InvalidUserLogin'
arguments: [ '@request_stack', '@current_route_match' ]
tags:
- { name: 'event_subscriber' }
google_analytics.pagepath.search:
class: '\Drupal\google_analytics\EventSubscriber\PagePath\Search'
arguments: [ '@config.factory', '@request_stack', '@module_handler', '@current_route_match' ]
tags:
- { name: 'event_subscriber' }
google_analytics.config.default_config:
class: '\Drupal\google_analytics\EventSubscriber\GoogleAnalyticsConfig\DefaultConfig'
arguments: [ '@config.factory', '@google_analytics.accounts', '@current_user' ]
tags:
- { name: 'event_subscriber' }
google_analytics.config.custom_config:
class: '\Drupal\google_analytics\EventSubscriber\GoogleAnalyticsConfig\CustomConfig'
arguments: [ '@config.factory', '@current_user', '@request_stack', '@token' ]
tags:
- { name: 'event_subscriber' }
\ No newline at end of file
......@@ -69,6 +69,9 @@
if ($('input#edit-google-analytics-trackmailto', context).is(':checked')) {
vals.push(Drupal.t('Mailto links'));
}
if ($('input#edit-google-analytics-tracktel', context).is(':checked')) {
vals.push(Drupal.t('Tel links'));
}
if ($('input#edit-google-analytics-trackfiles', context).is(':checked')) {
vals.push(Drupal.t('Downloads'));
}
......
......@@ -35,21 +35,19 @@
else if (drupalSettings.google_analytics.trackDownload && Drupal.google_analytics.isDownload(this.href)) {
// Download link clicked.
console.info("Download url '%s' has been found. Tracked download as extension '%s'.", Drupal.google_analytics.getPageUrl(this.href), Drupal.google_analytics.getDownloadExtension(this.href).toUpperCase());
ga('send', {
hitType: 'event',
eventCategory: 'Downloads',
eventAction: Drupal.google_analytics.getDownloadExtension(this.href).toUpperCase(),
eventLabel: Drupal.google_analytics.getPageUrl(this.href),
transport: 'beacon'
gtag('event', Drupal.google_analytics.getDownloadExtension(this.href).toUpperCase(), {
event_category: 'Downloads',
event_label: Drupal.google_analytics.getPageUrl(this.href),
transport_type: 'beacon'
});
}
else if (Drupal.google_analytics.isInternalSpecial(this.href)) {
// Keep the internal URL for Google Analytics website overlay intact.
console.info("Click on internal special link '%s' has been tracked.", Drupal.google_analytics.getPageUrl(this.href));
ga('send', {
hitType: 'pageview',
page: Drupal.google_analytics.getPageUrl(this.href),
transport: 'beacon'
// @todo: May require tracking ID
gtag('config', drupalSettings.google_analytics.account, {
page_path: Drupal.google_analytics.getPageUrl(this.href),
transport_type: 'beacon'
});
}
else {
......@@ -61,24 +59,29 @@
if (drupalSettings.google_analytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
// Mailto link clicked.
console.info("Click on e-mail '%s' has been tracked.", this.href.substring(7));
ga('send', {
hitType: 'event',
eventCategory: 'Mails',
eventAction: 'Click',
eventLabel: this.href.substring(7),
transport: 'beacon'
gtag('event', 'Click', {
event_category: 'Mails',
event_label: this.href.substring(7),
transport_type: 'beacon'
});
}
else if (drupalSettings.google_analytics.trackTel && $(this).is("a[href^='tel:'],area[href^='tel:']")) {
// Tel link clicked.
console.info("Click on telephone number '%s' has been tracked.", this.href.substring(4));
gtag('event', 'Click', {
event_category: 'Telephone calls',
event_label: this.href.substring(4),
transport_type: 'beacon'
});
}
else if (drupalSettings.google_analytics.trackOutbound && this.href.match(/^\w+:\/\//i)) {
if (drupalSettings.google_analytics.trackDomainMode !== 2 || (drupalSettings.google_analytics.trackDomainMode === 2 && !Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains))) {
// External link clicked / No top-level cross domain clicked.
console.info("Outbound link '%s' has been tracked.", this.href);
ga('send', {
hitType: 'event',
eventCategory: 'Outbound links',
eventAction: 'Click',
eventLabel: this.href,
transport: 'beacon'
gtag('event', 'Click', {
event_category: 'Outbound links',
event_label: this.href,
transport_type: 'beacon'
});
}
else {
......@@ -95,9 +98,8 @@
if (drupalSettings.google_analytics.trackUrlFragments) {
window.onhashchange = function () {
console.info("Track URL '%s' as pageview. Hash '%s' has changed.", location.pathname + location.search + location.hash, location.hash);
ga('send', {
hitType: 'pageview',
page: location.pathname + location.search + location.hash
gtag('config', drupalSettings.google_analytics.account, {
page_path: location.pathname + location.search + location.hash
});
};
}
......@@ -109,9 +111,8 @@
var href = $.colorbox.element().attr('href');
if (href) {
console.info("Colorbox transition to url '%s' has been tracked.", Drupal.google_analytics.getPageUrl(href));
ga('send', {
hitType: 'pageview',
page: Drupal.google_analytics.getPageUrl(href)
gtag('config', drupalSettings.google_analytics.account, {
page_path: Drupal.google_analytics.getPageUrl(href)
});
}
});
......
......@@ -31,43 +31,45 @@
// for download tracking?
else if (drupalSettings.google_analytics.trackDownload && Drupal.google_analytics.isDownload(this.href)) {
// Download link clicked.
ga('send', {
hitType: 'event',
eventCategory: 'Downloads',
eventAction: Drupal.google_analytics.getDownloadExtension(this.href).toUpperCase(),
eventLabel: Drupal.google_analytics.getPageUrl(this.href),
transport: 'beacon'
gtag('event', Drupal.google_analytics.getDownloadExtension(this.href).toUpperCase(), {
event_category: 'Downloads',
event_label: Drupal.google_analytics.getPageUrl(this.href),
transport_type: 'beacon'
});
}
else if (Drupal.google_analytics.isInternalSpecial(this.href)) {
// Keep the internal URL for Google Analytics website overlay intact.
ga('send', {
hitType: 'pageview',
page: Drupal.google_analytics.getPageUrl(this.href),
transport: 'beacon'
// @todo: May require tracking ID
gtag('config', drupalSettings.google_analytics.account, {
page_path: Drupal.google_analytics.getPageUrl(this.href),
transport_type: 'beacon'
});
}
}
else {
if (drupalSettings.google_analytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) {
// Mailto link clicked.
ga('send', {
hitType: 'event',
eventCategory: 'Mails',
eventAction: 'Click',
eventLabel: this.href.substring(7),
transport: 'beacon'
gtag('event', 'Click', {
event_category: 'Mails',
event_label: this.href.substring(7),
transport_type: 'beacon'
});
}
else if (drupalSettings.google_analytics.trackTel && $(this).is("a[href^='tel:'],area[href^='tel:']")) {
// Tel link clicked.
gtag('event', 'Click', {
event_category: 'Telephone calls',
event_label: this.href.substring(4),
transport_type: 'beacon'
});
}
else if (drupalSettings.google_analytics.trackOutbound && this.href.match(/^\w+:\/\//i)) {
if (drupalSettings.google_analytics.trackDomainMode !== 2 || (drupalSettings.google_analytics.trackDomainMode === 2 && !Drupal.google_analytics.isCrossDomain(this.hostname, drupalSettings.google_analytics.trackCrossDomains))) {
// External link clicked / No top-level cross domain clicked.
ga('send', {
hitType: 'event',
eventCategory: 'Outbound links',
eventAction: 'Click',
eventLabel: this.href,
transport: 'beacon'
gtag('event', 'Click', {
event_category: 'Outbound links',
event_label: this.href,
transport_type: 'beacon'
});
}
}
......@@ -78,9 +80,8 @@
// Track hash changes as unique pageviews, if this option has been enabled.
if (drupalSettings.google_analytics.trackUrlFragments) {
window.onhashchange = function () {
ga('send', {
hitType: 'pageview',
page: location.pathname + location.search + location.hash
gtag('config', drupalSettings.google_analytics.account, {
page_path: location.pathname + location.search + location.hash
});
};
}
......@@ -91,9 +92,8 @@
$(document).on('cbox_complete', function () {
var href = $.colorbox.element().attr('href');
if (href) {
ga('send', {
hitType: 'pageview',
page: Drupal.google_analytics.getPageUrl(href)
gtag('config', drupalSettings.google_analytics.account, {
page_path: Drupal.google_analytics.getPageUrl(href)
});
}
});
......
......@@ -33,7 +33,7 @@ source:
- googleanalytics_translation_set
- googleanalytics_visibility
- googleanalytics_visibility_roles
source_module: googleanalytics
source_module: googleanalytics
process:
account: googleanalytics_account
cache: googleanalytics_cache
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment