Skip to content

Commit 4baf1dc

Browse files
committed
Support for Google Analytics 4
1 parent cbee476 commit 4baf1dc

16 files changed

Lines changed: 322 additions & 481 deletions

File tree

UPGRADE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Upgrade guide
22

33
- [Upgrading to 1.1 from 1.0](#upgrade-1.1)
4+
- [Upgrading to 2.0 from 1.3](#upgrade-2.0)
45

56
<a name="upgrade-1.1"></a>
67
## Upgrading To 1.1
@@ -19,4 +20,7 @@ The Profile ID number has also changed, follow these settings to find the new on
1920
1. Click the **Admin** main menu tab again and select **View > View Settings** from the menu. *Copy to your clipboard* the Profile ID (should be a number).
2021
1. Paste this number in the **Analytics View/Profile ID number** field in the October back-end settings form.
2122

22-
> **Note**: This plugin does not support GAv4. If you are having issues creating an account, use the **Show advanced options** link in the GA Account creation and the **Create a Universal Analytics property** switch.
23+
<a name="upgrade-2.0"></a>
24+
## Upgrading To 2.0
25+
26+
Google will stop processing data for Universal Google Analytics on July 1, 2023. You will need to create a Google Analytics 4 property, upgrade the plugin, and configure it to access the new property. Refer to the plugin documentation for a detailed description of the configuration process.

classes/Analytics.php

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?php namespace RainLab\GoogleAnalytics\Classes;
22

33
use App;
4-
use Config;
5-
use Google_Client;
6-
use Google_Cache_File;
7-
use Google_Service_Analytics;
8-
use Google_Auth_AssertionCredentials;
4+
5+
use Google\Analytics\Data\V1beta\BetaAnalyticsDataClient;
96
use ApplicationException;
107
use RainLab\GoogleAnalytics\Models\Settings;
118

@@ -14,19 +11,14 @@ class Analytics
1411
use \October\Rain\Support\Traits\Singleton;
1512

1613
/**
17-
* @var Google_Client Google API client
14+
* @var Google\Analytics\Data\V1beta\BetaAnalyticsDataClient
1815
*/
1916
public $client;
2017

2118
/**
22-
* @var Google_Service_Analytics Google API analytics service
23-
*/
24-
public $service;
25-
26-
/**
27-
* @var string Google Analytics View ID
19+
* @var string Google Analytics Property ID
2820
*/
29-
public $viewId;
21+
public $propertyId;
3022

3123
protected function init()
3224
{
@@ -39,27 +31,10 @@ protected function init()
3931
throw new ApplicationException(trans('rainlab.googleanalytics::lang.strings.keynotuploaded'));
4032
}
4133

42-
$client = new Google_Client();
43-
44-
/*
45-
* Set caching
46-
*/
47-
$cache = App::make(CacheItemPool::class);
48-
$client->setCache($cache);
49-
50-
/*
51-
* Set assertion credentials
52-
*/
53-
$auth = json_decode($settings->gapi_key->getContents(), true);
54-
$client->setAuthConfig($auth);
55-
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
56-
57-
if ($client->isAccessTokenExpired()) {
58-
$client->refreshTokenWithAssertion();
59-
}
34+
$this->client = new BetaAnalyticsDataClient([
35+
'credentials' => $settings->gapi_key->getLocalPath()
36+
]);
6037

61-
$this->client = $client;
62-
$this->service = new Google_Service_Analytics($client);
63-
$this->viewId = 'ga:'.$settings->profile_id;
38+
$this->propertyId = $settings->profile_id;
6439
}
6540
}

classes/CacheItem.php

Lines changed: 0 additions & 116 deletions
This file was deleted.

classes/CacheItemPool.php

Lines changed: 0 additions & 181 deletions
This file was deleted.

components/tracker/default.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
gtag('set', { 'anonymize_ip': true });
1414
{% endif %}
1515
gtag('config', '{{ __SELF__.trackingId }}');
16-
</script>
16+
</script>

0 commit comments

Comments
 (0)