templates/gate/gate-sdk.html.twig line 1

Open in your IDE?
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>{% block title %}Welcome!{% endblock %}</title>
  6.     <link rel="icon"
  7.           href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>">
  8.     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css"
  9.           integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
  10.     <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
  11.             integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
  12.             crossorigin="anonymous"></script>
  13.     <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"
  14.             integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF"
  15.             crossorigin="anonymous"></script>
  16.     {# Axeptio TCF API #}
  17.     <script>
  18.         window.axeptioSettings = {
  19.             clientId: "66137db6ae83de5e566cfc53",
  20.             cookiesVersion: "first-id sandbox-fr-EU",
  21.         };
  22.         (function (d, s) {
  23.             var t = d.getElementsByTagName(s)[0],
  24.                 e = d.createElement(s);
  25.             e.async = false;
  26.             e.src = "//static.axept.io/tcf/sdk.js";
  27.             e.type = "module";
  28.             t.parentNode.insertBefore(e, t);
  29.         })(document, "script");
  30.     </script>
  31.     {# End Axeptio TCF API #}
  32. </head>
  33. <body>
  34. <nav class="navbar navbar-expand-lg navbar-light bg-light">
  35.     <a class="navbar-brand" href="{{ path('app_index') }}">{{ site_name }}</a>
  36.     <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
  37.             aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  38.         <span class="navbar-toggler-icon"></span>
  39.     </button>
  40. </nav>
  41. <div class="container">
  42.     <div class="row">
  43.         <div class="col-md-12">
  44.             <h3>First ID : <span id="firstid"></span></h3>
  45.         </div>
  46.     </div>
  47.     <div class="row mt-4">
  48.         <div class="col-md-12">
  49.             <h4>DeviceId:</h4>
  50.             <input type="text" id="deviceIdInput" class="mb-2 form-control" disabled>
  51.             <button id="generateDeviceId" class="btn btn-secondary">Get device id</button>
  52.         </div>
  53.     </div>
  54.     <div class="row mt-4">
  55.         <div class="col-md-12">
  56.             {% if not hasFirstId %}
  57.                 <button id="redirectButton" class="btn btn-primary">Get First ID</button>
  58.             {% else %}
  59.                 <p>You already have a First ID.</p>
  60.             {% endif %}
  61.         </div>
  62.     </div>
  63.     {% block body %}{% endblock %}
  64. </div>
  65. <script>
  66.     const FIRSTID_VENDOR_ID = 1178;
  67.     function listenForTCFConsent(callback) {
  68.         console.debug('Listening for TCF consent...');
  69.         if (!window.__tcfapi) return;
  70.         window.__tcfapi('addEventListener', 2, (tcData, success) => {
  71.             if (success && tcData.gdprApplies) {
  72.                 if (tcData.vendor.consents[FIRSTID_VENDOR_ID] && tcData.eventStatus === 'useractioncomplete') {
  73.                     console.log('User consented to the flex feature.');
  74.                     callback();
  75.                 } else {
  76.                     console.log('User did not consent to the flex feature.');
  77.                 }
  78.             } else {
  79.                 console.log('__tcfapi failed to load or is not applicable.');
  80.             }
  81.         });
  82.     }
  83.     listenForTCFConsent(window.location.reload)
  84.     function getCookieValueFromCookieName(cookieName) {
  85.         let cookieArr = document.cookie.split(";");
  86.         for (let i = 0; i < cookieArr.length; i++) {
  87.             let cookiePair = cookieArr[i].split("=");
  88.             if (cookieName === cookiePair[0].trim()) {
  89.                 return decodeURIComponent(cookiePair[1]);
  90.             }
  91.         }
  92.         return null;
  93.     }
  94.     function checkFirstidCookie() {
  95.         let firstidCookieValue = getCookieValueFromCookieName("firstid");
  96.         if (firstidCookieValue) {
  97.             console.log(`First ID : ${firstidCookieValue}`)
  98.         } else {
  99.             console.log('No First ID cookie found.')
  100.         }
  101.     }
  102.     function loadFirstIdSdk() {
  103.         console.time("sdk:callback");
  104.         console.time("sdk:event");
  105.         var script = document.createElement('script');
  106.         script.src = "https://cdn.preprod.first-id.fr/sdk/loader/loader.min.js";
  107.         script.defer = true;
  108.         document.head.appendChild(script);
  109.         script.onload = function () {
  110.             window.firstId = window.firstId || {
  111.                 callbacks: [],
  112.                 debug: true,
  113.                 cookieName: 'firstid'
  114.             };
  115.             window.firstId.callbacks.push(() => {
  116.                 console.log('FirstID SDK loaded and initialized after user consent.');
  117.                 console.timeEnd("sdk:callback");
  118.             });
  119.             window.firstId.callbacks.push(() => {
  120.                 console.log(FIRSTID.get)
  121.             });
  122.         };
  123.     }
  124.     function checkConsentAndLoadSdk() {
  125.         let consent = getCookieValueFromCookieName('consent');
  126.         if (consent === 'yes') {
  127.             loadFirstIdSdk();
  128.         }
  129.     }
  130.     checkConsentAndLoadSdk();
  131.     checkFirstidCookie();
  132.     loadFirstIdSdk()
  133.     let fid = getCookieValueFromCookieName('firstid')
  134.     if (fid) {
  135.         $('#firstid').text(fid)
  136.     } else {
  137.         $('#firstid').text('No First ID cookie found.')
  138.     }
  139.     document.getElementById('redirectButton')?.addEventListener('click', function() {
  140.         window.location.href = "{{ path('app_gate_sdk_redirect') }}";
  141.     });
  142.     document.addEventListener('firstId:new', (event) => console.log('New first id:', event.detail));
  143.     document.addEventListener('firstId:initialized', (event) => {
  144.         console.log('First id initialized:', event.detail)
  145.         console.timeEnd("sdk:event");
  146.     });
  147.     document.getElementById('generateDeviceId').addEventListener('click', function() {
  148.         if(!window.FIRSTID) {
  149.             console.error('FirstID SDK not loaded yet.');
  150.             return;
  151.         }
  152.         if(!window.FIRSTID.getDeviceId) {
  153.             console.error('FirstID SDK does not have getDeviceId method.');
  154.             return;
  155.         }
  156.         FIRSTID.getDeviceId()
  157.             .then(id => {
  158.                 document.getElementById('deviceIdInput').value = id;
  159.             })
  160.             .catch(error => {
  161.                 console.error('Error:', error);
  162.             });
  163.     });
  164. </script>
  165. </body>
  166. </html>