Skip to content

Commit 089eae1

Browse files
committed
Support secure cookies over https
1 parent e6798b6 commit 089eae1

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

event/listener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function load_google_analytics()
8080
'GOOGLEANALYTICS_TAG' => $this->config['googleanalytics_tag'],
8181
'GOOGLEANALYTICS_USER_ID' => $this->user->data['user_id'],
8282
'S_ANONYMIZE_IP' => $this->config['ga_anonymize_ip'],
83+
'S_COOKIE_SECURE' => $this->config['cookie_secure'],
8384
]);
8485
}
8586

styles/all/template/event/overall_header_stylesheets_after.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{%- EVENT phpbb_googleanalytics_gtag_options -%}
1414
{%- if S_REGISTERED_USER %}'user_id': '{{ GOOGLEANALYTICS_USER_ID }}',{% endif -%}
1515
{%- if S_ANONYMIZE_IP %}'anonymize_ip': true,{% endif -%}
16+
{%- if S_COOKIE_SECURE -%}'cookie_flags': 'samesite=none;secure',{%- endif -%}
1617
});
1718
</script>
1819
{% else %}
@@ -25,6 +26,7 @@
2526
ga('create', '{{ GOOGLEANALYTICS_ID }}', 'auto');
2627
{% if S_REGISTERED_USER %}ga('set', 'userId', {{ GOOGLEANALYTICS_USER_ID }});{% endif %}
2728
{% if S_ANONYMIZE_IP %}ga('set', 'anonymizeIp', true);{% endif %}
29+
{% if S_COOKIE_SECURE %}ga('set', 'cookie_flags', 'samesite=none;secure');{% endif %}
2830
{% EVENT phpbb_googleanalytics_alter_ga_requirements -%}
2931
ga('send', 'pageview');
3032
</script>

tests/event/listener_test.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ protected function setUp(): void
4848
// Load/Mock classes required by the event listener class
4949
$this->config = new \phpbb\config\config([
5050
'googleanalytics_id' => 'UA-000000-01',
51+
'googleanalytics_tag' => 1,
5152
'ga_anonymize_ip' => 0,
53+
'cookie_secure' => 0,
5254
]);
5355
$this->template = $this->getMockBuilder('\phpbb\template\template')
5456
->getMock();
@@ -108,6 +110,7 @@ public function test_load_google_analytics()
108110
'GOOGLEANALYTICS_TAG' => $this->config['googleanalytics_tag'],
109111
'GOOGLEANALYTICS_USER_ID' => $this->user->data['user_id'],
110112
'S_ANONYMIZE_IP' => $this->config['ga_anonymize_ip'],
113+
'S_COOKIE_SECURE' => $this->config['cookie_secure'],
111114
]);
112115

113116
$dispatcher = new \phpbb\event\dispatcher();

0 commit comments

Comments
 (0)