CookiesConsent.vue 15 KB

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