1st commit
This commit is contained in:
33
wco/tracker/consentform.mustache
Normal file
33
wco/tracker/consentform.mustache
Normal file
@@ -0,0 +1,33 @@
|
||||
<style>
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-100px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-fadeIn {
|
||||
animation: fadeIn 2s ease-out;
|
||||
}
|
||||
</style>
|
||||
<div class="tracker bg-white rounded-lg shadow-lg p-6 w-full max-w-md md:max-w-lg lg:max-w-xl xl:max-w-2xl animate-fadeIn">
|
||||
<!-- Texte d'information sur les cookies -->
|
||||
<div class="mb-4">
|
||||
<p class="text-sm text-gray-700">
|
||||
{{introtext}}
|
||||
<a href="{{CGU}}" target="_blank" class="text-blue-500 hover:underline">{{{CGUlabel}}}</a>
|
||||
</p>
|
||||
</div>
|
||||
<!-- Boutons d'action -->
|
||||
<div class="flex flex-col space-y-2">
|
||||
{{#btn}}
|
||||
<button class="btn btn-primary w-full" onclick="apx.tracker.setconsent('{{tagid}}','{{action}}')">
|
||||
{{{text}}}
|
||||
</button>
|
||||
{{/btn}}
|
||||
</div>
|
||||
</div>
|
19
wco/tracker/exampleform_en.json
Normal file
19
wco/tracker/exampleform_en.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"CGU": "https://smatchit.io/Smatchit_RGPD_app_web_fr.html",
|
||||
"CGUlabel": "Terms of Service",
|
||||
"introtext": "In accordance with the GDPR, we need your permission to store your personal data on this site. If you 'refuse all recording', you will not have access to the content with identification. If you wish to support us, your data may be shared with third parties. Please consult our terms and conditions for more information:",
|
||||
"btn": [
|
||||
{
|
||||
"action": "acceptfullcookies",
|
||||
"text": "I accept to support this site"
|
||||
},
|
||||
{
|
||||
"action": "acceptstatisticcookies",
|
||||
"text": "I accept only to facilitate navigation"
|
||||
},
|
||||
{
|
||||
"action": "refusecookies",
|
||||
"text": "I refuse all recording"
|
||||
}
|
||||
]
|
||||
}
|
19
wco/tracker/exampleform_fr.json
Normal file
19
wco/tracker/exampleform_fr.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"CGU": "https://smatchit.io/Smatchit_RGPD_app_web_fr.html",
|
||||
"CGUlabel": "Conditions générales d'utilisation",
|
||||
"introtext": "Conformément au RGPD, nous devons obtenir votre autorisation pour stocker vos données personnelles sur ce site. Si vous 'refusez tout enregistrement', vous n'aurez pas accès au contenu avec identification. Si vous souhaitez nous soutenir, vos données pourront être communiquées à des tiers. Consultez nos conditions pour en savoir plus :",
|
||||
"btn": [
|
||||
{
|
||||
"action": "acceptfullcookies",
|
||||
"text": "J'accepte pour soutenir ce site"
|
||||
},
|
||||
{
|
||||
"action": "acceptstatisticcookies",
|
||||
"text": "J'accepte uniquement pour faciliter la navigation"
|
||||
},
|
||||
{
|
||||
"action": "refusecookies",
|
||||
"text": "Je refuse tout enregistrement"
|
||||
}
|
||||
]
|
||||
}
|
140
wco/tracker/tracker.js
Normal file
140
wco/tracker/tracker.js
Normal file
@@ -0,0 +1,140 @@
|
||||
var apx = apx || {};
|
||||
apx.tracker = {};
|
||||
apx.tracker.getinfodevice = async () => {
|
||||
const device = {};
|
||||
//console.log(navigator);
|
||||
device.useragent = navigator.userAgent || navigator.vendor || window.opera;
|
||||
device.typedevice = /iPad/i.test(device.useragent) ? "ipad" : "";
|
||||
device.typedevice = /iPhone/i.test(device.useragent) ? "iphone" : "";
|
||||
device.typedevice = /iPod/i.test(device.useragent) ? "ipod" : "";
|
||||
device.typedevice = /Android/i.test(device.useragent) ? "android" : "";
|
||||
device.typedevice =
|
||||
device.typedevice == "" &&
|
||||
/Windows NT|Macintosh|Linux/i.test(device.useragent)
|
||||
? "PC"
|
||||
: "";
|
||||
console.log(
|
||||
"test linux",
|
||||
/Windows NT|Macintosh|Linux/i.test(device.useragent)
|
||||
);
|
||||
device.type =
|
||||
device.type === "" && /Mobi/i.test(device.userAgent) ? "mobile" : "";
|
||||
device.os = /Windows NT/i.test(device.useragent) ? "windows" : "";
|
||||
device.os = /Macintosh/i.test(device.useragent) ? "mac" : "";
|
||||
device.os = /Linux/i.test(device.useragent) ? "linux" : "";
|
||||
const ipinfo = await axios.get("https://ipinfo.io/json");
|
||||
console.log(ipinfo);
|
||||
if (
|
||||
ipinfo &&
|
||||
ipinfo.data &&
|
||||
ipinfo.data !== null &&
|
||||
typeof ipinfo.data === "object" &&
|
||||
Object.keys(ipinfo.data).length > 0
|
||||
) {
|
||||
if (ipinfo.data.ip) device.ip = ipinfo.data.ip;
|
||||
if (ipinfo.data.city) device.city = ipinfo.data.city;
|
||||
if (ipinfo.data.country) device.country = ipinfo.data.country;
|
||||
}
|
||||
device.screenWidth = window.screen.width;
|
||||
device.screenHeight = window.screen.height;
|
||||
const connection =
|
||||
navigator.connection ||
|
||||
navigator.mozConnection ||
|
||||
navigator.webkitConnection;
|
||||
if (connection) {
|
||||
device.connection = `${connection.effectiveType}_${connection.downlink} Mbps`;
|
||||
}
|
||||
device.lang = navigator.language;
|
||||
device.plugins = Array.from(navigator.plugins).map((plugin) => plugin.name);
|
||||
//console.log(device)
|
||||
return device;
|
||||
};
|
||||
apx.tracker.hit = (data) => {
|
||||
if (!data.consentcookie && localStorage.getItem("consentcookie"))
|
||||
data.consentcookie = localStorage.getItem("consentcookie");
|
||||
if (!data.lasttm && localStorage.getItem("lasttm"))
|
||||
data.lasttm = localStorage.getItem("lasttm");
|
||||
if (!data.xuuid && localStorage.getItem("xuuid"))
|
||||
data.xuuid = localStorage.getItem("xuuid");
|
||||
if (!data.xapp && localStorage.getItem("xapp"))
|
||||
data.xapp = localStorage.getItem("xapp");
|
||||
if (apx.data.headers.xalias != "anonymous")
|
||||
data.alias = apx.data.headers.xalias;
|
||||
let missing = "";
|
||||
[("xapp", "srckey", "xuuid", "lasttm", "consentcookie")].forEach((k) => {
|
||||
missing += !data[k] ? `${k},` : "";
|
||||
});
|
||||
if (missing !== "") {
|
||||
console.log(`Check your trktag ${missing} are missing`);
|
||||
return;
|
||||
}
|
||||
let urltrack = "/trk/cdn/trkret/empty.json?";
|
||||
Object.keys(data).forEach((d) => {
|
||||
urltrack += `d=${data[d]}&`;
|
||||
});
|
||||
urltrack = urltrack.slice(0, -1);
|
||||
//console.log(urltrack);
|
||||
axios.get(urltrack);
|
||||
};
|
||||
apx.tracker.load = () => {
|
||||
if (!localStorage.getItem("consentcookie")) {
|
||||
document
|
||||
.querySelectorAll('div:not([wco-name="tracker"])')
|
||||
.forEach((el) => {
|
||||
el.classList.add("opacity-40");
|
||||
el.style.pointerEvents = "auto";
|
||||
});
|
||||
document.querySelectorAll("[wco-name='tracker']").forEach((el) => {
|
||||
const tpldata = `${apx.data.pagename}_${el.id}_trackerconsentform`;
|
||||
if (!apx.data.tpldata[tpldata] || !apx.data.tpldata[tpldata].introtext) {
|
||||
console.log(` ${tpldata} does not exist check your file`);
|
||||
} else {
|
||||
el.innerHTML = Mustache.render(
|
||||
apx.data.tpl.trackerconsentform,
|
||||
apx.data.tpldata[tpldata]
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// test if last loading was <10minutes then send a new tag
|
||||
const tm = dayjs().valueOf();
|
||||
const lasttmtxt = localStorage.getItem("lasttm");
|
||||
const lasttm = lasttmtxt ? Number(lasttmtxt) : null;
|
||||
//console.log(lasttm, tm, tm - lasttm > 10 * 60 * 1000);
|
||||
if (lasttm && tm - lasttm > 10 * 60 * 1000) {
|
||||
localStorage.setItem("lasttm", tm);
|
||||
apx.tracker.hit({ srckey: "visitwwws" });
|
||||
}
|
||||
}
|
||||
};
|
||||
apx.tracker.setconsent = async (tagid, choice) => {
|
||||
//localStorage.setItem("consentcookie", choice);
|
||||
if (!localStorage.getItem("xuuid")) {
|
||||
const uuid = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
|
||||
(
|
||||
c ^
|
||||
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
|
||||
).toString(16)
|
||||
);
|
||||
localStorage.setItem("xuuid", uuid);
|
||||
apx.data.headers.xuuid = uuid;
|
||||
const tm = dayjs().valueOf();
|
||||
localStorage.setItem("lasttm", tm);
|
||||
apx.save();
|
||||
}
|
||||
if (["acceptstatisticcookies", "acceptfullcookies"].includes(choice)) {
|
||||
const infodevice = await apx.tracker.getinfodevice();
|
||||
//console.log(infodevice);
|
||||
axios.post(`/api/apxtri/trackings/newdevice`, infodevice, {
|
||||
headers: apx.data.headers,
|
||||
});
|
||||
}
|
||||
apx.tracker.hit({ srckey: "firstvisitwwws" });
|
||||
document.querySelectorAll('div:not([wco-name="tracker"])').forEach((el) => {
|
||||
el.classList.remove("opacity-40");
|
||||
el.style.pointerEvents = "auto";
|
||||
});
|
||||
document.getElementById(tagid).classList.add("hidden");
|
||||
};
|
||||
|
||||
apx.readyafterupdate(apx.tracker.load);
|
Reference in New Issue
Block a user