Skip to content

Commit 84af585

Browse files
[IMP] website_cookiefirst: Replace deprecated Cookiefirst functionality
- replace banner.js with new consent.js script using domain and identifier
1 parent 0bb9c55 commit 84af585

8 files changed

Lines changed: 70 additions & 22 deletions

File tree

website_cookiefirst/README.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ To configure this module, you need to:
4444

4545
1. Go to **Website > Configuration > Settings**
4646
2. Search 'Cookiefirst' option.
47-
3. Fill in your 'Cookiefirst ID' (e.g.
48-
'00000000-0000-0000-0000-000000000000').
49-
4. Click on "Save" button.
47+
3. Enable Use Cookiefirst checkbox
48+
4. Enter your Cookiefirst **API Key** into **Cookiefirst ID** field
49+
(e.g. '00000000-0000-0000-0000-000000000000').
50+
5. Enter your website domain in the **Domain** field (e.g.,
51+
mydomain.com).
52+
6. Click on "Save" button.
5053

5154
⚠️ **Please note: if another cookie consent solution is installed (e.g.
5255
Cookiebot), the execution of the Cookiefirst script will be prevented.

website_cookiefirst/models/res_config_settings.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ def _compute_cookiefirst_enabled(self):
1515
def _inverse_cookiefirst_enabled(self):
1616
for record in self:
1717
if not record.cookiefirst_enabled:
18-
record.website_id.update({"cookiefirst_identifier": False})
18+
record.website_id.update(
19+
{
20+
"cookiefirst_identifier": False,
21+
"cookiefirst_domain": False,
22+
}
23+
)
1924

2025
cookiefirst_identifier = fields.Char(
2126
string="Cookiefirst ID",
2227
related="website_id.cookiefirst_identifier",
2328
readonly=False,
2429
)
30+
cookiefirst_domain = fields.Char(
31+
string="Domain",
32+
related="website_id.cookiefirst_domain",
33+
readonly=False,
34+
)
2535
cookiefirst_enabled = fields.Boolean(
2636
string="Use Cookiefirst",
2737
compute="_compute_cookiefirst_enabled",

website_cookiefirst/models/website.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ class Website(models.Model):
1111
string="Cookiefirst ID",
1212
help="This field holds the ID, needed for Cookiefirst functionality.",
1313
)
14+
cookiefirst_domain = fields.Char(
15+
string="Domain",
16+
help="Domain used for Cookiefirst consent.js URL.",
17+
)

website_cookiefirst/readme/CONFIGURE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ To configure this module, you need to:
22

33
1. Go to **Website \> Configuration \> Settings**
44
2. Search 'Cookiefirst' option.
5-
3. Fill in your 'Cookiefirst ID' (e.g.
5+
3. Enable Use Cookiefirst checkbox
6+
4. Enter your Cookiefirst **API Key** into **Cookiefirst ID** field (e.g.
67
'00000000-0000-0000-0000-000000000000').
7-
4. Click on "Save" button.
8+
5. Enter your website domain in the **Domain** field (e.g., mydomain.com).
9+
6. Click on "Save" button.
810

911
⚠️ **Please note: if another cookie consent solution is
1012
installed (e.g. Cookiebot), the execution of the Cookiefirst

website_cookiefirst/static/description/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,11 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
392392
<ol class="arabic simple">
393393
<li>Go to <strong>Website &gt; Configuration &gt; Settings</strong></li>
394394
<li>Search ‘Cookiefirst’ option.</li>
395-
<li>Fill in your ‘Cookiefirst ID’ (e.g.
396-
‘00000000-0000-0000-0000-000000000000’).</li>
395+
<li>Enable Use Cookiefirst checkbox</li>
396+
<li>Enter your Cookiefirst <strong>API Key</strong> into <strong>Cookiefirst ID</strong> field
397+
(e.g. ‘00000000-0000-0000-0000-000000000000’).</li>
398+
<li>Enter your website domain in the <strong>Domain</strong> field (e.g.,
399+
mydomain.com).</li>
397400
<li>Click on “Save” button.</li>
398401
</ol>
399402
<p>⚠️ <strong>Please note: if another cookie consent solution is installed (e.g.

website_cookiefirst/tests/test_website.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ class TestWebsite(TransactionCase):
88
def setUp(self):
99
super().setUp()
1010
self.website = self.env["website"].create(
11-
{"name": "Test Website", "cookiefirst_identifier": "1234567890"}
11+
{
12+
"name": "Test Website",
13+
"cookiefirst_identifier": "1234567890",
14+
"cookiefirst_domain": "example.com",
15+
}
1216
)
1317

1418
def test_cookiefirst_identifier(self):
1519
self.assertEqual(self.website.cookiefirst_identifier, "1234567890")
20+
21+
def test_cookiefirst_domain(self):
22+
self.assertEqual(self.website.cookiefirst_domain, "example.com")

website_cookiefirst/views/res_config_settings_views.xml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,30 @@
1111
<setting id="website_cookiefirst" help="Add Cookiefirst functionality">
1212
<field name="cookiefirst_enabled" />
1313
<div class="mt16" invisible="not cookiefirst_enabled">
14-
<label
15-
class="col-md-3 o_light_label"
16-
string="Tracking ID"
17-
for="cookiefirst_identifier"
18-
/>
19-
<field
20-
name="cookiefirst_identifier"
21-
required="cookiefirst_enabled"
22-
placeholder="00000000-0000-0000-0000-000000000000"
23-
/>
14+
<div class="row">
15+
<label
16+
class="col-md-3 o_light_label"
17+
string="Tracking ID"
18+
for="cookiefirst_identifier"
19+
/>
20+
<field
21+
name="cookiefirst_identifier"
22+
required="cookiefirst_enabled"
23+
placeholder="00000000-0000-0000-0000-000000000000"
24+
/>
25+
</div>
26+
<div class="row">
27+
<label
28+
class="col-md-3 o_light_label"
29+
string="Domain"
30+
for="cookiefirst_domain"
31+
/>
32+
<field
33+
name="cookiefirst_domain"
34+
required="cookiefirst_enabled"
35+
placeholder="domain.com"
36+
/>
37+
</div>
2438
</div>
2539
</setting>
2640
</xpath>

website_cookiefirst/views/website_template.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717
<attribute name="data-cookiefirst-category">performance</attribute>
1818
</xpath>
1919
<xpath expr="//script[last()]" position="after">
20-
<t t-if="website.cookiefirst_identifier">
20+
<t t-if="website.cookiefirst_domain and website.cookiefirst_identifier">
2121
<script
22-
src="https://consent.cookiefirst.com/banner.js"
23-
t-att-data-cookiefirst-key="website.cookiefirst_identifier"
22+
t-att-src="(
23+
'https://consent.cookiefirst.com/sites/' +
24+
website.cookiefirst_domain + '-' +
25+
website.cookiefirst_identifier +
26+
'/consent.js'
27+
)"
2428
/>
2529
</t>
2630
</xpath>
2731
</template>
32+
2833
</odoo>

0 commit comments

Comments
 (0)