CookiesConsent.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <template>
  2. <div v-if="layoutStore.isCookieConsentDialogVisible">
  3. <div v-if="!showCustomizationOptions" class="cookie-consent-banner">
  4. <div class="continue-wrapper">
  5. <a class="continue" href="#" @click.prevent="continueWithoutAccepting">
  6. Continuer sans accepter
  7. </a>
  8. <v-icon
  9. size="20"
  10. class="fa-solid fa-arrow-right ml-6"
  11. @click="closePopup()"
  12. />
  13. </div>
  14. <v-row justify="center">
  15. <v-col cols="12">
  16. <img
  17. src="/images/components/cookie-consent/A_cute_and_beautiful_illustration_of_a_cookie_list-removebg-preview.png"
  18. alt="Cookie"
  19. class="cookie-image"
  20. />
  21. </v-col>
  22. </v-row>
  23. <v-row no-gutters>
  24. <v-col cols="12">
  25. <div class="text">
  26. <p>GESTION DES COOKIES</p>
  27. </div>
  28. </v-col>
  29. </v-row>
  30. <p class="details-cookies" style="padding-left: 20px">
  31. Le site Opentalent.fr utilise des cookies fonctionnels nécessaires à la
  32. navigation du site et d'autres technologies similaire pour plusieurs
  33. objectifs : des cookies d'analyse de l'audience du site, des cookies de
  34. personnalisation de contenu et des cookies publicitaires. Pour plus de
  35. détail, veuillez consulter notre
  36. <NuxtLink to="/politique-de-confidentialite#cookie-policy">
  37. Politique de confidentialité</NuxtLink
  38. >. Vous pouvez ajuster vos préférences en matière de cookies à tout
  39. moment en cliquant sur le bouton "Gérer mes préférences"
  40. </p>
  41. <div class="horizontal-line"></div>
  42. <div class="actions">
  43. <button
  44. class="customize-button"
  45. @click="showCustomizationOptions = true"
  46. >
  47. Gérer mes préférences
  48. </button>
  49. <button class="accept-button" @click="acceptAllCookies">
  50. Tout accepter
  51. </button>
  52. <!-- <button class="decline-button" @click="declineCookies">Refuser</button> -->
  53. </div>
  54. </div>
  55. <v-dialog v-model="showCustomizationOptions" :fullscreen="mdAndDown">
  56. <v-card>
  57. <v-row class="headline">
  58. <v-btn
  59. class="close-dialog"
  60. :icon="true"
  61. @click="showCustomizationOptions = false"
  62. >
  63. <v-icon size="20" class="fas fa-times" />
  64. </v-btn>
  65. <v-card-title>Gérer mes préferences</v-card-title>
  66. </v-row>
  67. <p class="gestion-preferences">
  68. Vous pouvez définir vos préférences sur la manière dont vous souhaitez
  69. que vos données soient utilisées en fonction des finalités et des
  70. entreprises tierces ci-dessous. Certains tiers peuvent traiter des
  71. données sur la base d'un intérêt légitime et vous pouvez choisir de
  72. vous désinscrire.
  73. </p>
  74. <v-container class="preferences-actions text-end">
  75. <button class="decline-button" @click="declineCookies">
  76. Tout refuser
  77. </button>
  78. <button class="accept-button" @click="acceptAllCookies">
  79. Tout accepter
  80. </button>
  81. </v-container>
  82. <v-card-text>
  83. <h4>Des cookies tiers permettant de réaliser des statistiques</h4>
  84. <v-row align="center">
  85. <v-col cols="auto">
  86. <v-switch
  87. v-model="cookiesPreferences.analyticsConsent"
  88. label="Mesure d'audience"
  89. hide-details
  90. color="green"
  91. inset
  92. />
  93. </v-col>
  94. <v-col>{{
  95. cookiesPreferences.analyticsConsent ? 'Autorisé' : 'Non-autorisé'
  96. }}</v-col>
  97. </v-row>
  98. <p>
  99. Ces cookies nous permettent d'établir des statistiques, des volumes
  100. de fréquentation et d'utilisation des divers éléments de notre site,
  101. nous permettant d’optimiser son fonctionnement.
  102. </p>
  103. <h4 class="mt-6">Des cookies tiers à visée publicitaire</h4>
  104. <v-row align="center">
  105. <v-col cols="auto">
  106. <v-switch
  107. v-model="cookiesPreferences.advertisingConsent"
  108. label="Suivi publicitaire"
  109. hide-details
  110. color="green"
  111. inset
  112. />
  113. </v-col>
  114. <v-col>{{
  115. cookiesPreferences.advertisingConsent
  116. ? 'Autorisé'
  117. : 'Non-autorisé'
  118. }}</v-col>
  119. </v-row>
  120. <p>
  121. Autoriser le stockage et l'accès aux cookies pour diffuser des
  122. annonces publicitaires personnalisées. Cela permet de vous montrer
  123. des publicités plus pertinentes.
  124. </p>
  125. <v-row align="center">
  126. <v-col cols="auto">
  127. <v-switch
  128. v-model="cookiesPreferences.adUserDataConsent"
  129. label="Données Utilisateur pour la Publicité"
  130. hide-details
  131. color="green"
  132. inset
  133. />
  134. </v-col>
  135. <v-col>{{
  136. cookiesPreferences.advertisingConsent
  137. ? 'Autorisé'
  138. : 'Non-autorisé'
  139. }}</v-col>
  140. </v-row>
  141. <p>
  142. Autoriser la collecte et l'utilisation de vos données personnelles
  143. (comme votre adresse e-mail ou numéro de téléphone) pour créer des
  144. profils de publicité personnalisés et améliorer le ciblage des
  145. annonces.
  146. </p>
  147. <v-row align="center">
  148. <v-col cols="auto">
  149. <v-switch
  150. v-model="cookiesPreferences.adPersonalizationConsent"
  151. label="Personnalisation des annonces"
  152. hide-details
  153. color="green"
  154. inset
  155. />
  156. </v-col>
  157. <v-col>{{
  158. cookiesPreferences.advertisingConsent
  159. ? 'Autorisé'
  160. : 'Non-autorisé'
  161. }}</v-col>
  162. </v-row>
  163. <p>
  164. Autoriser la personnalisation des annonces en fonction de vos
  165. préférences et de votre comportement de navigation pour vous offrir
  166. des publicités plus pertinentes et ciblées.
  167. </p>
  168. </v-card-text>
  169. <v-card-actions>
  170. <v-btn color="secondary" @click="showCustomizationOptions = false">
  171. Fermer
  172. </v-btn>
  173. <v-spacer />
  174. <button class="accept-button" @click="saveCookiesPreferences">
  175. Sauvegarder
  176. </button>
  177. </v-card-actions>
  178. </v-card>
  179. </v-dialog>
  180. </div>
  181. <v-alert
  182. v-model="showNotification"
  183. title="Confirmation"
  184. type="warning"
  185. width="400"
  186. closable
  187. transition="fade-transition"
  188. density="compact"
  189. class="alert"
  190. >
  191. Vous avez refusé nos cookies. Si vous le souhaitez, vous pouvez encore
  192. modifier votre décision en
  193. <a href="#" @click="showPopup()">cliquant ici</a>.
  194. </v-alert>
  195. </template>
  196. <script setup lang="ts">
  197. import { onMounted, type Ref, ref } from 'vue'
  198. import { useCookies } from 'vue3-cookies'
  199. import { useDisplay } from 'vuetify'
  200. import { COOKIE_CONSENT_CHOICE } from '~/types/enum/enums'
  201. import type { CookiesPreferences } from '~/types/interface'
  202. const layoutStore = useLayoutStore()
  203. const { mdAndDown } = useDisplay()
  204. const { cookies } = useCookies()
  205. const showCustomizationOptions = ref(false)
  206. const showNotification = ref(false)
  207. const { gtag, initialize: initializeGTag } = useGtag()
  208. /**
  209. * Cookies options
  210. */
  211. const cookiesPreferences: Ref<CookiesPreferences> = ref({
  212. consent: COOKIE_CONSENT_CHOICE.NONE,
  213. analyticsConsent: true,
  214. advertisingConsent: true,
  215. adUserDataConsent: true,
  216. adPersonalizationConsent: true,
  217. })
  218. /**
  219. * Affiche la popup de choix de consentement aux cookies
  220. */
  221. const showPopup = () => {
  222. layoutStore.setIsCookieConsentDialogVisible(true)
  223. }
  224. /**
  225. * Ferme la popup de choix de consentement aux cookies
  226. */
  227. const closePopup = () => {
  228. layoutStore.setIsCookieConsentDialogVisible(false)
  229. showCustomizationOptions.value = false
  230. showNotification.value = false
  231. }
  232. /**
  233. * Affiche une notification d'une minute pour permettre à l'utilisateur qui
  234. * a refusé les cookies de changer d'avis
  235. */
  236. const notify = () => {
  237. showNotification.value = true
  238. // Hide the notification after 1 minute
  239. setTimeout(() => {
  240. showNotification.value = false
  241. }, 60000)
  242. }
  243. /**
  244. * Créé ou supprime les cookies selon les préférences en cours
  245. *
  246. * @param duration Durée de vie des cookies (en jours, défaut : 365)
  247. */
  248. const setupCookies = (duration: number = 365) => {
  249. // Enregistre les préférences actuelles dans 2 cookies
  250. cookies.set(
  251. 'cookie_consent',
  252. cookiesPreferences.value.consent,
  253. duration + 'd'
  254. )
  255. cookies.set(
  256. 'cookie_preferences',
  257. JSON.stringify({
  258. analyticsConsent: cookiesPreferences.value.analyticsConsent,
  259. advertisingConsent: cookiesPreferences.value.advertisingConsent,
  260. adUserDataConsent: cookiesPreferences.value.adUserDataConsent,
  261. adPersonalizationConsent:
  262. cookiesPreferences.value.adPersonalizationConsent,
  263. }),
  264. duration + 'd'
  265. )
  266. // Initialise et paramètre google tag manager
  267. initializeGTag()
  268. gtag('consent', 'update', {
  269. analytics_storage: cookiesPreferences.value.analyticsConsent
  270. ? 'granted'
  271. : 'denied',
  272. ad_storage: cookiesPreferences.value.advertisingConsent
  273. ? 'granted'
  274. : 'denied',
  275. ad_user_data: cookiesPreferences.value.adUserDataConsent
  276. ? 'granted'
  277. : 'denied',
  278. ad_personalization: cookiesPreferences.value.adPersonalizationConsent
  279. ? 'granted'
  280. : 'denied',
  281. })
  282. // Nettoie les cookies si ceux ci ne sont plus les bienvenus
  283. // TODO: voir si ce nettoyage manuel est nécessaire, ou si google tag manager ne peut pas s'en occuper
  284. if (!cookiesPreferences.value.analyticsConsent) {
  285. purgeAnalyticsCookies()
  286. }
  287. if (!cookiesPreferences.value.advertisingConsent) {
  288. purgeAdvertisingCookies()
  289. }
  290. // Enregistre la date et le contenu de la dernière acceptation (comme trace)
  291. localStorage.setItem(
  292. 'cookie_consent',
  293. JSON.stringify({
  294. date: new Date(),
  295. consent: cookiesPreferences.value,
  296. })
  297. )
  298. }
  299. /**
  300. * Nettoie les cookies google analytics
  301. */
  302. const purgeAnalyticsCookies = () => {
  303. cookies.remove('_ga')
  304. cookies.remove('_gat')
  305. cookies.remove('_gid')
  306. cookies.keys().forEach((name) => {
  307. if (/_ga_\w{10}/.test(name)) {
  308. cookies.remove(name)
  309. }
  310. })
  311. }
  312. /**
  313. * Nettoie les cookies meta pixel
  314. */
  315. const purgeAdvertisingCookies = () => {
  316. cookies.remove('_fbp')
  317. }
  318. /**
  319. * Accept and setup all the cookies and close the popup
  320. */
  321. const acceptAllCookies = () => {
  322. cookiesPreferences.value = {
  323. consent: COOKIE_CONSENT_CHOICE.ACCEPTED,
  324. analyticsConsent: true,
  325. advertisingConsent: true,
  326. adUserDataConsent: true,
  327. adPersonalizationConsent: true,
  328. }
  329. setupCookies()
  330. closePopup()
  331. }
  332. /**
  333. * Refuse all the cookies, set up the cookie_consent cookie and close the popup
  334. */
  335. const declineCookies = () => {
  336. cookiesPreferences.value = {
  337. consent: COOKIE_CONSENT_CHOICE.DECLINED,
  338. analyticsConsent: false,
  339. advertisingConsent: false,
  340. adUserDataConsent: false,
  341. adPersonalizationConsent: false,
  342. }
  343. setupCookies(7)
  344. notify()
  345. closePopup()
  346. }
  347. /**
  348. * Set up the cookies following user preferences and close the popup
  349. */
  350. const saveCookiesPreferences = () => {
  351. cookiesPreferences.value.consent = COOKIE_CONSENT_CHOICE.CUSTOMIZED
  352. setupCookies()
  353. closePopup()
  354. }
  355. /**
  356. * Continue without accepting cookies
  357. */
  358. const continueWithoutAccepting = () => {
  359. closePopup()
  360. }
  361. /**
  362. * Charge les préférences depuis les cookies
  363. */
  364. const loadActivePreferences = () => {
  365. const cookieConsentVal = cookies.get('cookie_consent')
  366. const cookiePreferencesVal = cookies.get('cookie_preferences')
  367. if (cookieConsentVal && cookiePreferencesVal) {
  368. cookiesPreferences.value = {
  369. consent: cookieConsentVal,
  370. // @ts-ignore
  371. ...cookiePreferencesVal,
  372. }
  373. }
  374. }
  375. /**
  376. * Check if the user has already accepted the cookies when page is mounted
  377. */
  378. onMounted(() => {
  379. loadActivePreferences()
  380. if (cookiesPreferences.value.consent === COOKIE_CONSENT_CHOICE.NONE) {
  381. showPopup()
  382. }
  383. })
  384. </script>
  385. <style scoped lang="scss">
  386. .gestion-preferences {
  387. font-size: 1.2rem;
  388. font-weight: 500;
  389. margin-bottom: 10px;
  390. padding: 20px;
  391. text-align: justify;
  392. }
  393. .preferences-actions {
  394. overflow: visible;
  395. }
  396. .headline {
  397. font-size: 1.5rem;
  398. font-weight: 500;
  399. margin: 0 0 10px 0;
  400. background-color: var(--secondary-color);
  401. color: var(--on-secondary-color);
  402. text-transform: uppercase;
  403. padding: 15px;
  404. }
  405. .cookie-consent-banner {
  406. background: var(--neutral-color);
  407. position: fixed;
  408. bottom: 10px;
  409. left: 15px;
  410. max-width: 550px;
  411. z-index: 10000 !important;
  412. display: flex;
  413. flex-direction: column;
  414. align-items: center;
  415. box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  416. border-radius: 15px;
  417. padding: 20px;
  418. @media (max-width: 600px) {
  419. max-height: 650px;
  420. overflow-y: scroll;
  421. bottom: unset;
  422. top: 50%;
  423. left: 50%;
  424. margin: auto;
  425. width: 90%;
  426. transform: translate(-50%, -50%);
  427. }
  428. }
  429. .cookie-image {
  430. width: 150px;
  431. margin: 0;
  432. }
  433. .text {
  434. padding-top: 10px;
  435. padding-bottom: 0;
  436. font-weight: 600;
  437. font-size: 1.3rem;
  438. text-align: center;
  439. }
  440. .details-cookies {
  441. padding: 10px;
  442. text-align: justify;
  443. }
  444. .horizontal-line {
  445. width: 90%;
  446. height: 1px;
  447. background-color: var(--neutral-color-alt-strong);
  448. margin-top: 10px;
  449. margin-bottom: 10px;
  450. }
  451. .actions {
  452. margin-top: 10px;
  453. margin-bottom: 10px;
  454. display: flex;
  455. justify-content: center;
  456. }
  457. .accept-button,
  458. .customize-button {
  459. background-color: var(--on-primary-color-alt);
  460. border: none;
  461. padding: 10px 20px;
  462. margin: 5px;
  463. cursor: pointer;
  464. }
  465. .decline-button {
  466. border: 1px solid var(--on-neutral-color);
  467. padding: 10px 20px;
  468. margin: 5px;
  469. cursor: pointer;
  470. }
  471. .accept-button:hover,
  472. .customize-button:hover {
  473. background-color: var(--on-primary-color-alt);
  474. }
  475. .cookie-description {
  476. margin: 0;
  477. font-size: 0.875rem;
  478. color: var(--on-neutral-color-light);
  479. }
  480. .custom-switch .v-input--selection-controls__ripple .v-ripple__container {
  481. background-color: var(--v-primary-color);
  482. }
  483. .custom-switch,
  484. .v-input--selection-controls__ripple--active,
  485. .v-ripple__container {
  486. background-color: var(--v-primary-darken4);
  487. }
  488. .custom-switch .v-input--selection-controls__input {
  489. --v-theme-primary: var(--v-primary-base);
  490. --v-theme-primary-lighten4: var(--v-primary-lighten4);
  491. --v-theme-primary-darken4: var(--v-primary-darken4);
  492. }
  493. .custom-switch,
  494. .v-input--selection-controls__input,
  495. input:checked,
  496. .v-input--selection-controls__ripple,
  497. .v-ripple__container {
  498. background-color: var(--v-primary-darken4);
  499. }
  500. .custom-switch,
  501. .v-input--selection-controls__input,
  502. input:checked,
  503. .v-input--selection-controls__ripple,
  504. .v-ripple__container,
  505. .v-ripple__animation {
  506. background-color: var(--v-primary-darken4);
  507. }
  508. :deep(.v-switch__track) {
  509. background-color: var(--warning-color);
  510. }
  511. .close-dialog {
  512. background: none !important;
  513. box-shadow: none !important;
  514. }
  515. .continue {
  516. font-size: 0.9rem;
  517. font-weight: 500;
  518. cursor: pointer;
  519. text-decoration: none !important;
  520. color: var(--on-neutral-color);
  521. }
  522. .continue-wrapper {
  523. display: flex;
  524. justify-content: end;
  525. align-items: center;
  526. margin-left: auto;
  527. }
  528. :deep(.v-switch .v-label) {
  529. opacity: 0.8;
  530. }
  531. .alert {
  532. position: fixed;
  533. bottom: 20px;
  534. right: 20px;
  535. z-index: 1000;
  536. a {
  537. color: var(--on-primary-color);
  538. font-weight: 700;
  539. text-decoration: none;
  540. }
  541. a:hover {
  542. text-decoration: underline;
  543. }
  544. }
  545. </style>