Skip to content

Commit 83d69c7

Browse files
committed
provide the necessary configurations as arguments rather than in the configuration file
1 parent 19f948b commit 83d69c7

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed

config/cookieconsent.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,4 @@
8585
'id' => env('GOOGLE_TAG_MANAGER_ID'),
8686
],
8787

88-
/* Google Tag Manager configuration
89-
|--------------------------------------------------------------------------
90-
|
91-
| These rules will define the data that Google Tag Manager will receive.
92-
|
93-
*/
94-
'gtm_consent' => [
95-
'ad_user_data',
96-
'ad_personalization',
97-
'ad_storage',
98-
'analytics_storage',
99-
]
10088
];

src/AnalyticCookiesCategory.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function getGroupCookies($group, $name, $id)
3333
/**
3434
* Define Google Analytics cookies all at once.
3535
*/
36-
public function google(string $id, bool $anonymizeIp = true): static
36+
public function googleAnalytics(string $id, bool $anonymizeIp = true): static
3737
{
3838
$this->group(function (CookiesGroup $group) use ($anonymizeIp, $id) {
3939
$anonymizeIp = $anonymizeIp === true ? 'true' : 'false';
@@ -50,15 +50,12 @@ public function google(string $id, bool $anonymizeIp = true): static
5050
return $this;
5151
}
5252

53-
public function gtm(string $id): static
53+
public function googleTagManager(string $id, $config): static
5454
{
55-
$consentSettings = config('cookieconsent.gtm_consent', [
56-
'ad_user_data',
57-
'ad_personalization',
58-
'ad_storage',
59-
'analytics_storage',
60-
]);
61-
$consentSettings = array_fill_keys($consentSettings, 'granted');
55+
app()->instance('cookieconsent.gtm.enabled', true);
56+
app()->instance('cookieconsent.gtm.config', $config);
57+
58+
$consentSettings = array_fill_keys($config, 'granted');
6259

6360
$consentJson = json_encode($consentSettings, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
6461

src/CookiesManager.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected function getConsentedScripts(bool $withDefault): string
199199

200200
protected function getDefaultScriptTag(): string
201201
{
202-
$gtmScript = config('cookieconsent.google_tag_manager.id') ? $this->getGTMScript() : null;
202+
$gtmScript = app()->has('cookieconsent.gtm.enabled') ? $this->getGTMScript() : null;
203203

204204
return '<script '
205205
. 'src="' . route('cookieconsent.script') . '?id='
@@ -214,12 +214,7 @@ protected function getDefaultScriptTag(): string
214214
*/
215215
private function getGTMScript()
216216
{
217-
$defaultSettings = config('cookieconsent.gtm_consent', [
218-
'ad_user_data',
219-
'ad_personalization',
220-
'ad_storage',
221-
'analytics_storage',
222-
]);
217+
$defaultSettings = app('cookieconsent.gtm.config');
223218

224219
$defaultSettings = array_fill_keys($defaultSettings, 'denied');
225220
$defaultSettings['wait_for_update'] = 500;

0 commit comments

Comments
 (0)