Skip to content

Commit

Permalink
Merge pull request #182 from felixaschultz/development
Browse files Browse the repository at this point in the history
Updating iframe for cookie sharing
  • Loading branch information
felixaschultz authored Aug 15, 2024
2 parents 1bef4d7 + 36e02d5 commit a9cd9c7
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 83 deletions.
9 changes: 8 additions & 1 deletion cb.js

Large diffs are not rendered by default.

75 changes: 36 additions & 39 deletions cookieSharingIframe.html
Original file line number Diff line number Diff line change
@@ -1,60 +1,57 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intastellar Cookie Sharing infos</title>
</head>

<body>
<script>
/* (function() {
"use strict"; */
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(";");
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === " ") {
c = c.substring(1);
}

/* console.log(localStorage.getItem(cname), cname); */

if (c.indexOf(name) === 0 && localStorage.getItem(cname) === null) {
return c.substring(name.length, c.length);
}else if(localStorage.getItem(cname) !== null){
return localStorage.getItem(cname);
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(";");
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === " ") {
c = c.substring(1);
}
return "";
}

window.addEventListener("message", (event) => {
const origin = event.origin || event.originalEvent.origin;
/* localStorage.setItem("cookieSharing", JSON.stringify(event.data)); */
const d = new Date();
const daysExpire = 1;
d.setTime(d.getTime()+(daysExpire * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toGMTString();

if(event.data.cookieSharing !== undefined){
document.cookie = "cookieSharing=" + event.data.cookieSharing + ";" + expires + ";path=/; SameSite=None; Secure";
/* console.log(localStorage.getItem(cname), cname); */

if (c.indexOf(name) === 0 && localStorage.getItem(cname) === null) {
return c.substring(name.length, c.length);
} else if (localStorage.getItem(cname) !== null) {
return localStorage.getItem(cname);
}
}
return "";
}

window.addEventListener("message", (event) => {
const origin = event.origin || event.originalEvent.origin;
console.log(event.data, origin);

localStorage.setItem("cookieSharing", event.data);

if (event.data == "you´re open to share with me") {
window.parent.postMessage({
cookieSharing: event.data,
}, "*");
}
/* if(event.data.sharingDomains.includes(origin.replace("https://", "").replace("http://", "").replace("www.", ""))){
if(event.data == "you´re open to share with me"){
window.parent.postMessage({
cookieSharing: event.data,
}, "*");
}
/* if(event.data.sharingDomains.includes(origin.replace("https://", "").replace("http://", "").replace("www.", ""))){
} */
} */

});
});

window.parent.postMessage("ready", "*");
window.parent.postMessage("ready", "*");
/* })(); */
</script>
</body>

</html>
75 changes: 35 additions & 40 deletions dev/cb.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const moreSettingsContent = document.createElement("section");
const moreintHeader = document.createElement("intheader");
const moreContentText = document.createElement("section");
const moreFooter = document.createElement("footer");
const intaconsents = document.createElement("intastellar-consents");
const intaconsents = document.createElement("intastellarconsents");
const pluginSource = findScriptParameter("utm_source") === undefined ? "Intastellar+Solutions+Cookiebanner" : findScriptParameter("utm_source");
window.platform = findScriptParameter("utm_source") === undefined ? "Manual" : findScriptParameter("utm_source");

Expand Down Expand Up @@ -93,43 +93,30 @@ function setIntastellarPartnerDomain() {
if (window.INTA.settings.partnerDomain === null) return

if (window.INTA.settings?.partnerDomain?.length > 0) {
window.INTA.settings?.partnerDomain?.forEach(function (partner) {
const partnerDomainIframe = document.createElement("iframe");
partnerDomainIframe.id = "intastellarCrossSiteCheck";
partnerDomainIframe.src = "https://" + partner + "?intastellarPartners=" + btoa(JSON.stringify({
int_staticsticCookies: intaCookieConsents?.staticsticCookies,
int_FunctionalCookies: intaCookieConsents?.functionalCookies,
int_hideCookieBannerName: getCookie(int_hideCookieBannerName),
int_marketingCookies: intaCookieConsents?.advertisementCookies,
uid: intaConsentsObjectVariable.uid
}));

const partnerDomainIframeNoScript = document.createElement("noscript");

const getIntastellarPartnerScript = document.createElement("script");
getIntastellarPartnerScript.async = true;
getIntastellarPartnerScript.src = "https://consent.intastellarsolutions.com/getPartner.js?v=1." + new Date().getTime();
partnerDomainIframe.style.display = "none";
partnerDomainIframeNoScript.appendChild(partnerDomainIframe);
if (!window.location.host.includes(partner)) {
document.body.appendChild(partnerDomainIframe);
}
})
}
}

/* setIntastellarPartnerDomain(); */
if (document.getElementById("intastellarCrossSiteCheck") != null) {
const instatellariframe = document.getElementById("intastellarCrossSiteCheck");
const iframeDoc = instatellariframe.contentDocument || instatellariframe.contentWindow.document;
if (iframeDoc.readyState == 'complete') {
//iframe.contentWindow.alert("Hello");
instatellariframe.contentWindow.addEventListener("load", function () {

})
const intastellarSharingIframe = document.createElement("iframe");
// intastellarSharingIframe.src = "https://consents.cdn.intastellarsolutions.com/cookieSharingIframe.html";
intastellarSharingIframe.src = "/cookieSharingIframe.html";
intastellarSharingIframe.id = "intastellarCrossSiteCheck";
intastellarSharingIframe.style.display = "none";
intastellarSharingIframe.style.position = "absolute";
intastellarSharingIframe.style.top = "-100%";
intastellarSharingIframe.style.left = "-100%";

console.log("Partner domain: ", window.INTA.settings.partnerDomain);
document.body.appendChild(intastellarSharingIframe);
if (document.getElementById("intastellarCrossSiteCheck") != null) {
const intastellariframe = document.getElementById("intastellarCrossSiteCheck");
window.addEventListener("message", function (event) {
if (event.origin !== "https://consents.cdn.intastellarsolutions.com") return;
if (event.data === "ready") {
intastellariframe.contentWindow.postMessage(intaConsentsObjectVariable, "https://consents.cdn.intastellarsolutions.com");
}
});
}
}
}

setIntastellarPartnerDomain();
IntastellarCookieConsent.inizilize(intaconsents)
/* - - - Set the intastellarCookieLanguageuage dependent messages */

const messages = {
Expand Down Expand Up @@ -774,10 +761,7 @@ if (document.querySelector(".intastellarCCPAContainer") != null) {
}

window.addEventListener("load", function () {
IntastellarCookieConsent.inizilize(
intaconsents
)
(adsbygoogle = window.adsbygoogle || []).pauseAdRequests = 0;
(adsbygoogle = window.adsbygoogle || []).pauseAdRequests = 0;
const temp = location.host.split('.').reverse();
const domain = encodeURI(temp[1] + '.' + temp[0]);
const trImage = document.createElement("iframe");
Expand All @@ -786,6 +770,9 @@ window.addEventListener("load", function () {
trImage.title = "Intastellar Solutions cookie sharing library";
trImage.src = intastellarCookieBannerRootDomain + "/cookieSharingIframe.html";

document.body.appendChild(trImage);
console.log(trImage);

gtag('set', {
'user_id': (getCookie(int_hideCookieBannerName)) ? JSON.parse(decodeIntaConsentsObject(getCookie(int_hideCookieBannerName)?.split(".")[2])).uid : intaConsentsObjectVariable.uid
});
Expand Down Expand Up @@ -816,6 +803,14 @@ window.addEventListener("load", function () {
intaConsentsObjectVariable.sharingDomains.push(domain);
})

if (window.INTA.settings?.partnerDomain) {
dataLayer.push({
"linker": {
"domains": window.INTA.settings?.partnerDomain
}
});
}

if (getCookie(int_hideCookieBannerName) == "" && getCookie(int_hideCookieBannerName).indexOf("__inta") == -1) {
document.querySelector(".intastellarCookieConstents").classList.add("--active");
}
Expand Down
5 changes: 2 additions & 3 deletions tests/test-on-site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- <script src="../../cb.js"></script> -->
<script src="../../dev/gdpr.dev.js"></script>
<script src="../../gdpr-consents.config.js"></script>
<script src="../../dev/gdpr.dev.js"></script>
<!-- <script async>
const newScript = document.createElement("script");
newScript.src = "../../dev/gdpr.dev.js";
Expand Down Expand Up @@ -275,7 +274,7 @@ <h2>Trustpilot</h2>
<div class="trustpilot-widget" data-locale="da-DK" data-template-id="56278e9abfbbba0bdcd568bc"
data-businessunit-id="610ed3ed70a16b001e886877" data-style-height="52px" data-style-width="100%"></div>
<!-- End TrustBox widget -->
</section> -->
</section>
</body>

</html>

0 comments on commit a9cd9c7

Please sign in to comment.