Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACC-2850 only display if cookie consented #132

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 50 additions & 47 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,62 +176,65 @@ module.exports.init = (appInfo = {}) => {
} = setAppInfoDefault(appInfo);
let surveyData;
let feedbackOverlay;

const cookieConsent = document.cookie.includes('FTCookieConsentGDPR=true')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Have we checked with the Ads & Privacy team to ensure that this is the correct way to check cookie consent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GlynnPhillips I did it this way based on how other teams were checking for this cookie, but I can ask them to make sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable then :) Thanks, just wanted to check because I know we spoke about a solution like this but I wasn't sure if my suggestions were good one :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for you to go ahead

const container = document.querySelector(`${containerSelector} .n-feedback__container`);
if (!container) {
// eslint-disable-next-line no-console
console.error('The container was not found on the page.');
throw new Error('The container was not found on the page.');
}
container.classList.remove('n-feedback--hidden');
populateContainer(container, domain);
const trigger = document.querySelector(`${containerSelector} .n-feedback__container .n-feedback__survey-trigger`);

const overlayId = `feedback-overlay-${containerSelector}`;

if (trigger) {
trigger.addEventListener('click', () => {
if (!feedbackOverlay) {
feedbackOverlay = new Overlay(overlayId, {
html: '<div class="feedback-overlay__loader-wrapper"><div class="o-loading o-loading--dark o-loading--large"></div></div>',
fullscreen: true,
class: 'feedback-overlay',
zindex: 1001,
customclose: '.n-feedback__survey__close-button'
});
}
if (!surveyData) {
getSurveyData(surveyId).then(data => {
if (!data || (data && data.length === 0)) {
// eslint-disable-next-line no-console
console.error('Bad survey data');
} else {
surveyData = data;
const html = surveyBuilder.buildSurvey(surveyData, surveyId, domain);
// TODO: Validate the html
if (!feedbackOverlay.visible) {
feedbackOverlay.open();
if (cookieConsent) {
container.classList.remove('n-feedback--hidden');
populateContainer(container, domain);
const trigger = document.querySelector(`${containerSelector} .n-feedback__container .n-feedback__survey-trigger`);

const overlayId = `feedback-overlay-${containerSelector}`;

if (trigger) {
trigger.addEventListener('click', () => {
if (!feedbackOverlay) {
feedbackOverlay = new Overlay(overlayId, {
html: '<div class="feedback-overlay__loader-wrapper"><div class="o-loading o-loading--dark o-loading--large"></div></div>',
fullscreen: true,
class: 'feedback-overlay',
zindex: 1001,
customclose: '.n-feedback__survey__close-button'
});
}
if (!surveyData) {
getSurveyData(surveyId).then(data => {
if (!data || (data && data.length === 0)) {
// eslint-disable-next-line no-console
console.error('Bad survey data');
} else {
surveyData = data;
const html = surveyBuilder.buildSurvey(surveyData, surveyId, domain);
// TODO: Validate the html
if (!feedbackOverlay.visible) {
feedbackOverlay.open();
}

feedbackOverlay.content.innerHTML = html;
setBehaviour(feedbackOverlay, surveyData, surveyId, appInfo);

// run Validation as soon as you display the first block
const firstBlock = document.querySelectorAll('.n-feedback__survey-block', feedbackOverlay.content)[0];
runValidation(firstBlock);
}
}).catch((err) => {
// In case survey fetch fails
feedbackOverlay.destroy();
container.classList.add('n-feedback--hidden');
trigger.classList.add('n-feedback--hidden');
// eslint-disable-next-line no-console
console.error('Failed to get survey data', err);
});
}

feedbackOverlay.content.innerHTML = html;
setBehaviour(feedbackOverlay, surveyData, surveyId, appInfo);

// run Validation as soon as you display the first block
const firstBlock = document.querySelectorAll('.n-feedback__survey-block', feedbackOverlay.content)[0];
runValidation(firstBlock);
}
}).catch((err) => {
// In case survey fetch fails
feedbackOverlay.destroy();
container.classList.add('n-feedback--hidden');
trigger.classList.add('n-feedback--hidden');
// eslint-disable-next-line no-console
console.error('Failed to get survey data', err);
});
}
toggleOverlay(feedbackOverlay);
}, true);
}

toggleOverlay(feedbackOverlay);
}, true);
}

return {
Expand Down