CookiesConsent.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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 {
  206. gtag,
  207. initialize: initializeGTag
  208. } = useGtag()
  209. /**
  210. * Cookies options
  211. */
  212. const cookiesPreferences: Ref<CookiesPreferences> = ref({
  213. consent: COOKIE_CONSENT_CHOICE.NONE,
  214. analyticsConsent: true,
  215. advertisingConsent: true,
  216. adUserDataConsent: true,
  217. adPersonalizationConsent: true,
  218. })
  219. const showPopup = () => {
  220. layoutStore.setIsCookieConsentDialogVisible(true)
  221. }
  222. const closePopup = () => {
  223. layoutStore.setIsCookieConsentDialogVisible(false)
  224. showCustomizationOptions.value = false
  225. showNotification.value = false
  226. }
  227. const notify = () => {
  228. showNotification.value = true
  229. // Hide the notification after 1 minute
  230. setTimeout(() => {
  231. showNotification.value = false
  232. }, 60000)
  233. }
  234. const setupCookies = (
  235. choice: COOKIE_CONSENT_CHOICE,
  236. analyticsConsent: boolean,
  237. advertisingConsent: boolean,
  238. adUserDataConsent: boolean,
  239. adPersonalizationConsent: boolean,
  240. duration: number = 365
  241. ) => {
  242. cookies.set('cookie_consent', choice, duration + 'd')
  243. initializeGTag()
  244. cookiesPreferences.value.analyticsConsent = analyticsConsent
  245. cookies.set('analytics_consent', analyticsConsent.toString(), duration + 'd')
  246. cookiesPreferences.value.advertisingConsent = advertisingConsent
  247. cookies.set(
  248. 'advertising_consent',
  249. advertisingConsent.toString(),
  250. duration + 'd'
  251. )
  252. cookiesPreferences.value.adUserDataConsent = adUserDataConsent
  253. cookies.set(
  254. 'ad_user_data_consent',
  255. adUserDataConsent.toString(),
  256. duration + 'd'
  257. )
  258. cookiesPreferences.value.adPersonalizationConsent = adPersonalizationConsent
  259. cookies.set(
  260. 'ad_personalization_consent',
  261. adPersonalizationConsent.toString(),
  262. duration + 'd'
  263. )
  264. gtag('consent', 'update', {
  265. analytics_storage: analyticsConsent ? 'granted' : 'denied',
  266. ad_storage: advertisingConsent ? 'granted' : 'denied',
  267. ad_user_data: adUserDataConsent ? 'granted' : 'denied',
  268. ad_personalization: adPersonalizationConsent ? 'granted' : 'denied',
  269. })
  270. if (!analyticsConsent) {
  271. purgeAnalyticsCookies()
  272. }
  273. // Store consent date and status
  274. localStorage.setItem(
  275. 'cookie_consent',
  276. JSON.stringify({
  277. date: new Date(),
  278. consent: {
  279. analyticsConsent,
  280. advertisingConsent,
  281. adUserDataConsent,
  282. adPersonalizationConsent,
  283. },
  284. })
  285. )
  286. }
  287. const purgeAnalyticsCookies = () => {
  288. cookies.remove('_ga')
  289. cookies.remove('_gat')
  290. cookies.remove('_gid')
  291. cookies.keys().forEach((name) => {
  292. if (/_ga_\w{10}/.test(name)) {
  293. cookies.remove(name)
  294. }
  295. })
  296. }
  297. /**
  298. * Accept and setup all the cookies and close the popup
  299. */
  300. const acceptAllCookies = () => {
  301. setupCookies(COOKIE_CONSENT_CHOICE.ACCEPTED, true, true, true, true)
  302. closePopup()
  303. }
  304. /**
  305. * Refuse all the cookies, set up the cookie_consent cookie and close the popup
  306. */
  307. const declineCookies = () => {
  308. setupCookies(COOKIE_CONSENT_CHOICE.DECLINED, false, false, false, false, 7)
  309. notify()
  310. closePopup()
  311. }
  312. /**
  313. * Set up the cookies following user preferences and close the popup
  314. */
  315. const saveCookiesPreferences = () => {
  316. setupCookies(
  317. COOKIE_CONSENT_CHOICE.CUSTOMIZED,
  318. cookiesPreferences.value.analyticsConsent,
  319. cookiesPreferences.value.advertisingConsent,
  320. cookiesPreferences.value.adUserDataConsent,
  321. cookiesPreferences.value.adPersonalizationConsent
  322. )
  323. closePopup()
  324. }
  325. /**
  326. * Continue without accepting cookies
  327. */
  328. const continueWithoutAccepting = () => {
  329. closePopup()
  330. }
  331. const loadActivePreferences = () => {
  332. const cookieConsent = cookies.get(
  333. 'cookie_consent'
  334. ) as COOKIE_CONSENT_CHOICE | null
  335. cookiesPreferences.value.consent =
  336. cookieConsent !== null ? cookieConsent : COOKIE_CONSENT_CHOICE.NONE
  337. cookiesPreferences.value.analyticsConsent =
  338. cookies.get('analytics_consent') !== 'false'
  339. cookiesPreferences.value.advertisingConsent =
  340. cookies.get('advertising_consent') !== 'false'
  341. cookiesPreferences.value.adUserDataConsent =
  342. cookies.get('ad_user_data_consent') !== 'false'
  343. cookiesPreferences.value.adPersonalizationConsent =
  344. cookies.get('ad_personalization_consent') !== 'false'
  345. }
  346. /**
  347. * Check if the user has already accepted the cookies when page is mounted
  348. */
  349. onMounted(() => {
  350. loadActivePreferences()
  351. if (cookiesPreferences.value.consent === COOKIE_CONSENT_CHOICE.NONE) {
  352. showPopup()
  353. }
  354. })
  355. </script>
  356. <style scoped lang="scss">
  357. .gestion-preferences {
  358. font-size: 1.2rem;
  359. font-weight: 500;
  360. margin-bottom: 10px;
  361. padding: 20px;
  362. text-align: justify;
  363. }
  364. .preferences-actions {
  365. overflow: visible;
  366. }
  367. .headline {
  368. font-size: 1.5rem;
  369. font-weight: 500;
  370. margin: 0 0 10px 0;
  371. background-color: var(--secondary-color);
  372. color: var(--on-secondary-color);
  373. text-transform: uppercase;
  374. padding: 15px;
  375. }
  376. .cookie-consent-banner {
  377. background: var(--neutral-color);
  378. position: fixed;
  379. bottom: 10px;
  380. left: 15px;
  381. max-width: 550px;
  382. z-index: 1000 !important;
  383. display: flex;
  384. flex-direction: column;
  385. align-items: center;
  386. box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  387. border-radius: 15px;
  388. padding: 20px;
  389. }
  390. .cookie-image {
  391. width: 150px;
  392. margin: 0;
  393. }
  394. .text {
  395. padding-top: 10px;
  396. padding-bottom: 0;
  397. font-weight: 600;
  398. font-size: 1.3rem;
  399. text-align: center;
  400. }
  401. .details-cookies {
  402. padding: 10px;
  403. text-align: justify;
  404. }
  405. .horizontal-line {
  406. width: 90%;
  407. height: 1px;
  408. background-color: var(--neutral-color-alt-strong);
  409. margin-top: 10px;
  410. margin-bottom: 10px;
  411. }
  412. .actions {
  413. margin-top: 10px;
  414. margin-bottom: 10px;
  415. display: flex;
  416. justify-content: center;
  417. }
  418. .accept-button,
  419. .customize-button {
  420. background-color: var(--on-primary-color-alt);
  421. border: none;
  422. padding: 10px 20px;
  423. margin: 5px;
  424. cursor: pointer;
  425. }
  426. .decline-button {
  427. border: 1px solid var(--on-neutral-color);
  428. padding: 10px 20px;
  429. margin: 5px;
  430. cursor: pointer;
  431. }
  432. .accept-button:hover,
  433. .customize-button:hover {
  434. background-color: var(--on-primary-color-alt);
  435. }
  436. .cookie-description {
  437. margin: 0;
  438. font-size: 0.875rem;
  439. color: var(--on-neutral-color-light);
  440. }
  441. .custom-switch .v-input--selection-controls__ripple .v-ripple__container {
  442. background-color: var(--v-primary-color);
  443. }
  444. .custom-switch,
  445. .v-input--selection-controls__ripple--active,
  446. .v-ripple__container {
  447. background-color: var(--v-primary-darken4);
  448. }
  449. .custom-switch .v-input--selection-controls__input {
  450. --v-theme-primary: var(--v-primary-base);
  451. --v-theme-primary-lighten4: var(--v-primary-lighten4);
  452. --v-theme-primary-darken4: var(--v-primary-darken4);
  453. }
  454. .custom-switch,
  455. .v-input--selection-controls__input,
  456. input:checked,
  457. .v-input--selection-controls__ripple,
  458. .v-ripple__container {
  459. background-color: var(--v-primary-darken4);
  460. }
  461. .custom-switch,
  462. .v-input--selection-controls__input,
  463. input:checked,
  464. .v-input--selection-controls__ripple,
  465. .v-ripple__container,
  466. .v-ripple__animation {
  467. background-color: var(--v-primary-darken4);
  468. }
  469. :deep(.v-switch__track) {
  470. background-color: var(--warning-color);
  471. }
  472. .close-dialog {
  473. background: none !important;
  474. box-shadow: none !important;
  475. }
  476. .continue {
  477. font-size: 0.9rem;
  478. font-weight: 500;
  479. cursor: pointer;
  480. text-decoration: none !important;
  481. color: var(--on-neutral-color);
  482. }
  483. .continue-wrapper {
  484. display: flex;
  485. justify-content: end;
  486. align-items: center;
  487. margin-left: auto;
  488. }
  489. :deep(.v-switch .v-label) {
  490. opacity: 0.8;
  491. }
  492. .alert {
  493. position: fixed;
  494. bottom: 20px;
  495. right: 20px;
  496. z-index: 1000;
  497. a {
  498. color: var(--on-primary-color);
  499. font-weight: 700;
  500. text-decoration: none;
  501. }
  502. a:hover {
  503. text-decoration: underline;
  504. }
  505. }
  506. </style>