CookiesConsent.vue 16 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. const setCookie = (keyName: string, value: string, duration: number) => {
  244. cookies.set(keyName, value, duration + 'd', '/', '.opentalent.fr')
  245. }
  246. /**
  247. * Créé ou supprime les cookies selon les préférences en cours
  248. *
  249. * @param duration Durée de vie des cookies (en jours, défaut : 365)
  250. */
  251. const setupCookies = (duration: number = 365) => {
  252. // Enregistre les préférences actuelles dans 2 cookies
  253. setCookie('cookie_consent', cookiesPreferences.value.consent, duration)
  254. setCookie(
  255. 'cookie_preferences',
  256. JSON.stringify({
  257. analyticsConsent: cookiesPreferences.value.analyticsConsent,
  258. advertisingConsent: cookiesPreferences.value.advertisingConsent,
  259. adUserDataConsent: cookiesPreferences.value.adUserDataConsent,
  260. adPersonalizationConsent:
  261. cookiesPreferences.value.adPersonalizationConsent,
  262. }),
  263. duration
  264. )
  265. // Initialise et paramètre google tag manager
  266. initializeGTag()
  267. gtag('consent', 'update', {
  268. analytics_storage: cookiesPreferences.value.analyticsConsent
  269. ? 'granted'
  270. : 'denied',
  271. ad_storage: cookiesPreferences.value.advertisingConsent
  272. ? 'granted'
  273. : 'denied',
  274. ad_user_data: cookiesPreferences.value.adUserDataConsent
  275. ? 'granted'
  276. : 'denied',
  277. ad_personalization: cookiesPreferences.value.adPersonalizationConsent
  278. ? 'granted'
  279. : 'denied',
  280. })
  281. // Nettoie les cookies si ceux ci ne sont plus les bienvenus
  282. // TODO: voir si ce nettoyage manuel est nécessaire, ou si google tag manager ne peut pas s'en occuper
  283. if (!cookiesPreferences.value.analyticsConsent) {
  284. purgeAnalyticsCookies()
  285. }
  286. if (!cookiesPreferences.value.advertisingConsent) {
  287. purgeAdvertisingCookies()
  288. }
  289. // Enregistre la date et le contenu de la dernière acceptation (comme trace)
  290. localStorage.setItem(
  291. 'cookie_consent',
  292. JSON.stringify({
  293. date: new Date(),
  294. consent: cookiesPreferences.value,
  295. })
  296. )
  297. }
  298. /**
  299. * Nettoie les cookies google analytics
  300. */
  301. const purgeAnalyticsCookies = () => {
  302. cookies.remove('_ga')
  303. cookies.remove('_gat')
  304. cookies.remove('_gid')
  305. cookies.keys().forEach((name) => {
  306. if (/_ga_\w{10}/.test(name)) {
  307. cookies.remove(name)
  308. }
  309. })
  310. }
  311. /**
  312. * Nettoie les cookies meta pixel
  313. */
  314. const purgeAdvertisingCookies = () => {
  315. cookies.remove('_fbp')
  316. }
  317. /**
  318. * Accept and setup all the cookies and close the popup
  319. */
  320. const acceptAllCookies = () => {
  321. cookiesPreferences.value = {
  322. consent: COOKIE_CONSENT_CHOICE.ACCEPTED,
  323. analyticsConsent: true,
  324. advertisingConsent: true,
  325. adUserDataConsent: true,
  326. adPersonalizationConsent: true,
  327. }
  328. setupCookies()
  329. closePopup()
  330. }
  331. /**
  332. * Refuse all the cookies, set up the cookie_consent cookie and close the popup
  333. */
  334. const declineCookies = () => {
  335. cookiesPreferences.value = {
  336. consent: COOKIE_CONSENT_CHOICE.DECLINED,
  337. analyticsConsent: false,
  338. advertisingConsent: false,
  339. adUserDataConsent: false,
  340. adPersonalizationConsent: false,
  341. }
  342. setupCookies(7)
  343. notify()
  344. closePopup()
  345. }
  346. /**
  347. * Set up the cookies following user preferences and close the popup
  348. */
  349. const saveCookiesPreferences = () => {
  350. cookiesPreferences.value.consent = COOKIE_CONSENT_CHOICE.CUSTOMIZED
  351. setupCookies()
  352. closePopup()
  353. }
  354. /**
  355. * Continue without accepting cookies
  356. */
  357. const continueWithoutAccepting = () => {
  358. closePopup()
  359. }
  360. /**
  361. * Charge les préférences depuis les cookies
  362. */
  363. const loadActivePreferences = () => {
  364. const cookieConsentVal = cookies.get('cookie_consent')
  365. const cookiePreferencesVal = cookies.get('cookie_preferences')
  366. if (cookieConsentVal && cookiePreferencesVal) {
  367. cookiesPreferences.value = {
  368. consent: cookieConsentVal,
  369. // @ts-ignore
  370. ...cookiePreferencesVal,
  371. }
  372. }
  373. }
  374. /**
  375. * Check if the user has already accepted the cookies when page is mounted
  376. */
  377. onMounted(() => {
  378. loadActivePreferences()
  379. if (cookiesPreferences.value.consent === COOKIE_CONSENT_CHOICE.NONE) {
  380. showPopup()
  381. }
  382. })
  383. </script>
  384. <style scoped lang="scss">
  385. .gestion-preferences {
  386. font-size: 1.2rem;
  387. font-weight: 500;
  388. margin-bottom: 10px;
  389. padding: 20px;
  390. text-align: justify;
  391. }
  392. .preferences-actions {
  393. overflow: visible;
  394. }
  395. .headline {
  396. font-size: 1.5rem;
  397. font-weight: 500;
  398. margin: 0 0 10px 0;
  399. background-color: var(--secondary-color);
  400. color: var(--on-secondary-color);
  401. text-transform: uppercase;
  402. padding: 15px;
  403. }
  404. .cookie-consent-banner {
  405. background: var(--neutral-color);
  406. position: fixed;
  407. bottom: 10px;
  408. left: 15px;
  409. max-width: 550px;
  410. z-index: 10000 !important;
  411. display: flex;
  412. flex-direction: column;
  413. align-items: center;
  414. box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  415. border-radius: 15px;
  416. padding: 20px;
  417. @media (max-width: 600px) {
  418. max-height: 650px;
  419. overflow-y: scroll;
  420. bottom: unset;
  421. top: 50%;
  422. left: 50%;
  423. margin: auto;
  424. width: 90%;
  425. transform: translate(-50%, -50%);
  426. }
  427. }
  428. .cookie-image {
  429. width: 150px;
  430. margin: 0;
  431. }
  432. .text {
  433. padding-top: 10px;
  434. padding-bottom: 0;
  435. font-weight: 600;
  436. font-size: 1.3rem;
  437. text-align: center;
  438. }
  439. .details-cookies {
  440. padding: 10px;
  441. text-align: justify;
  442. }
  443. .horizontal-line {
  444. width: 90%;
  445. height: 1px;
  446. background-color: var(--neutral-color-alt-strong);
  447. margin-top: 10px;
  448. margin-bottom: 10px;
  449. }
  450. .actions {
  451. margin-top: 10px;
  452. margin-bottom: 10px;
  453. display: flex;
  454. justify-content: center;
  455. }
  456. .accept-button,
  457. .customize-button {
  458. background-color: var(--on-primary-color-alt);
  459. border: none;
  460. padding: 10px 20px;
  461. margin: 5px;
  462. cursor: pointer;
  463. }
  464. .decline-button {
  465. border: 1px solid var(--on-neutral-color);
  466. padding: 10px 20px;
  467. margin: 5px;
  468. cursor: pointer;
  469. }
  470. .accept-button:hover,
  471. .customize-button:hover {
  472. background-color: var(--on-primary-color-alt);
  473. }
  474. .cookie-description {
  475. margin: 0;
  476. font-size: 0.875rem;
  477. color: var(--on-neutral-color-light);
  478. }
  479. .custom-switch .v-input--selection-controls__ripple .v-ripple__container {
  480. background-color: var(--v-primary-color);
  481. }
  482. .custom-switch,
  483. .v-input--selection-controls__ripple--active,
  484. .v-ripple__container {
  485. background-color: var(--v-primary-darken4);
  486. }
  487. .custom-switch .v-input--selection-controls__input {
  488. --v-theme-primary: var(--v-primary-base);
  489. --v-theme-primary-lighten4: var(--v-primary-lighten4);
  490. --v-theme-primary-darken4: var(--v-primary-darken4);
  491. }
  492. .custom-switch,
  493. .v-input--selection-controls__input,
  494. input:checked,
  495. .v-input--selection-controls__ripple,
  496. .v-ripple__container {
  497. background-color: var(--v-primary-darken4);
  498. }
  499. .custom-switch,
  500. .v-input--selection-controls__input,
  501. input:checked,
  502. .v-input--selection-controls__ripple,
  503. .v-ripple__container,
  504. .v-ripple__animation {
  505. background-color: var(--v-primary-darken4);
  506. }
  507. :deep(.v-switch__track) {
  508. background-color: var(--warning-color);
  509. }
  510. .close-dialog {
  511. background: none !important;
  512. box-shadow: none !important;
  513. }
  514. .continue {
  515. font-size: 0.9rem;
  516. font-weight: 500;
  517. cursor: pointer;
  518. text-decoration: none !important;
  519. color: var(--on-neutral-color);
  520. }
  521. .continue-wrapper {
  522. display: flex;
  523. justify-content: end;
  524. align-items: center;
  525. margin-left: auto;
  526. }
  527. :deep(.v-switch .v-label) {
  528. opacity: 0.8;
  529. }
  530. .alert {
  531. position: fixed;
  532. bottom: 20px;
  533. right: 20px;
  534. z-index: 1000;
  535. a {
  536. color: var(--on-primary-color);
  537. font-weight: 700;
  538. text-decoration: none;
  539. }
  540. a:hover {
  541. text-decoration: underline;
  542. }
  543. }
  544. </style>