Skip to content

Commit 1ae9224

Browse files
Merge pull request #835 from FitzwilliamMuseum/hotfix/analytics-fix
Cleaner analytics
2 parents 4b0200b + 7834680 commit 1ae9224

33 files changed

+396
-116
lines changed

app/Http/Controllers/landingPageController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
use App\Models\Exhibitions;
1414

1515
use Illuminate\Contracts\View\View;
16-
use Illuminate\Http\Request;
1716
use Illuminate\Http\Response;
1817
use Illuminate\Support\Facades\Route;
1918
use App\Models\FloorPlans;
2019

2120
class landingPageController extends Controller
2221
{
22+
public static function injectPages(string $slug = ''): array
23+
{
24+
return LandingPageTemplate::getLanding($slug);
25+
}
2326
/**
24-
* @return View
27+
* @param string $slug
28+
* @return View|Response
29+
* @throws InvalidArgumentException
2530
*/
2631
public function index($slug = '')
2732
{

app/Models/LandingPageTemplate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class LandingPageTemplate extends Model
1313
protected static string $table = 'landing_page_template';
1414

1515
/**
16+
* @param string $section
1617
* @return array
1718
*/
1819
public static function getLanding(string $slug = ''): array
@@ -24,6 +25,7 @@ public static function getLanding(string $slug = ''): array
2425
'meta' => '*',
2526
'filter[slug][eq]' => $slug,
2627
'filter[page_template][eq]' => 'landing',
28+
'filter[slug][eq]' => $slug
2729
)
2830
);
2931
return $api->getData();

public/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/js/app.js": "/js/app.js?id=485572c52c3cb1a197870005c67f956b",
2+
"/js/app.js": "/js/app.js?id=490bce15c2508c5b88061671cde8f380",
33
"/js/image-gallery.js": "/js/image-gallery.js?id=d69a0e28c98ea4361c052ddbf98dd62d",
44
"/js/events-carousel.js": "/js/events-carousel.js?id=89e31d3ded01942246c364c48d936947",
55
"/css/app.css": "/css/app.css?id=880d35bb8b03cfe31ab3a81983fef778",

resources/css/site.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ a.text-center.btn.btn-outline-light.btn__book {
11221122
background: transparent;
11231123
}
11241124

1125-
11261125
.col-max-800 {
11271126
max-width: 800px;
11281127
margin: 56px auto;

resources/js/config.js

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ CookieConsent.run({
5555
}, {
5656
title: 'Analytics cookies',
5757
description: 'These cookies collect information about how you use our website. All of the data is anonymized and cannot be used to identify you.',
58-
toggle: {
59-
value: 'analytics', // there are no default categories => you specify them
60-
enabled: true,
61-
readonly: false
62-
},
58+
// toggle: {
59+
// value: 'analytics', // there are no default categories => you specify them
60+
// enabled: true,
61+
// readonly: false
62+
// },
63+
linkedCategory: 'analytics',
6364
cookieTable: {
6465
caption: 'Cookie table',
6566
headers: {
@@ -87,11 +88,12 @@ CookieConsent.run({
8788
}, {
8889
title: 'Marketing cookies',
8990
description: "These cookies are used for advertising, including serving and rendering ads, personalizing ads (depending on your ad settings at <a href=\"https://g.co/adsettings\">g.co/adsettings</a>), limiting the number of times an ad is shown to a user, muting ads you have chosen to stop seeing, and measuring the effectiveness of ads.",
90-
toggle: {
91-
value: 'marketing',
92-
enabled: true,
93-
readonly: false
94-
},
91+
// toggle: {
92+
// value: 'marketing',
93+
// enabled: true,
94+
// readonly: false
95+
// },
96+
linkedCategory: 'marketing',
9597
cookieTable: {
9698
caption: 'Cookie table',
9799
headers: {
@@ -188,6 +190,42 @@ CookieConsent.run({
188190

189191
onConsent: function (cookie) {
190192
gtag('consent', 'update', {'analytics_storage': 'granted', 'ad_storage': 'granted', 'ad_personalization': 'granted', 'ad_user_data': 'granted'});
193+
// Find all soundcloud embeds on the page and block the src of their iframe if cookies aren't accepted
194+
let soundcloudEmbeds = document.querySelectorAll('.soundcloud-embed-component');
195+
196+
if(soundcloudEmbeds && soundcloudEmbeds.length > 0) {
197+
198+
console.log(cookie.cookie);
199+
200+
soundcloudEmbeds.forEach(embed => {
201+
202+
let embedContainer = embed.querySelector('.container');
203+
let iframeEl = embed.querySelector('iframe');
204+
const iframeSrc = iframeEl.src;
205+
206+
if(cookie.cookie.categories.includes('analytics')) {
207+
// Remove any classes blocking interaction
208+
if(embed.classList.contains('cookies-rejected')) {
209+
embed.classList.remove('cookiesRejected');
210+
if(embedContainer.querySelector('.cookies-rejected__message')) {
211+
let cookiesMessage = embedContainer.querySelector('.cookies-rejected__message');
212+
embedContainer.removeChild(cookiesMessage);
213+
}
214+
if(iframeEl.src == '') {
215+
iframeEl.src = iframeSrc;
216+
}
217+
}
218+
} else {
219+
iframeEl.src = 'about:blank';
220+
embed.classList.add('cookies-rejected')
221+
let cookiesText = document.createElement('p');
222+
cookiesText.classList.add('cookies-rejected__message');
223+
cookiesText.innerHTML = 'You must accept analytics cookies to view this media';
224+
embedContainer.appendChild(cookiesText);
225+
}
226+
227+
})
228+
}
191229
},
192230

193231
onChange: function (cookie, changed_preferences) {

resources/js/consentchecker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

resources/sass/exhibition/_hero.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,14 @@
5353
}
5454

5555
}
56+
57+
@media screen and ( min-width: 800px ) {
58+
.home-hero .addon.rise-up {
59+
align-items: flex-start;
60+
margin-top: 200px;
61+
}
62+
63+
.wrapper.rise-up {
64+
align-items: flex-end;
65+
}
66+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.soundcloud-embed-component {
2+
padding-inline: 1rem;
3+
4+
.container {
5+
padding: 0;
6+
}
7+
}
8+
.cookies-rejected {
9+
.container {
10+
position: relative;
11+
z-index: 3;
12+
13+
p {
14+
display: block;
15+
left: 50%;
16+
padding-inline: rem(20);
17+
position: absolute;
18+
text-align: center;
19+
top: 50%;
20+
transform: translate(-50%, -50%);
21+
width: 100%;
22+
z-index: 2;
23+
}
24+
25+
&:before {
26+
background: #ccc;
27+
content: "";
28+
display: block;
29+
position: absolute;
30+
height: 100%;
31+
width: 100%;
32+
z-index: 1;
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)