gdpr-consent
Version:
GDPR banner to comply with the European cookie law. Inspired by tarteaucitronjs.
48 lines (47 loc) • 1.58 kB
JavaScript
import { addScript } from "../utils/index.js";
export const googleads = ((user) => {
const googleIdentifier = user.googleadsId;
let tagUaCookie = "_gat_gtag_" + googleIdentifier;
let tagGCookie = "_ga_" + googleIdentifier;
tagUaCookie = tagUaCookie.replace(/-/g, "_");
tagGCookie = tagGCookie.replace(/G-/g, "");
return {
key: "googleads",
type: "analytic",
name: "Google Ads",
uri: "https://policies.google.com/privacy",
needConsent: true,
lazyConsent: false,
cookies: [
"_ga",
"_gat",
"_gid",
"__utma",
"__utmb",
"__utmc",
"__utmt",
"__utmz",
tagUaCookie,
tagGCookie,
"_gcl_au",
],
js: function () {
window.dataLayer = window.dataLayer || [];
addScript("https://www.googletagmanager.com/gtag/js?id=" + user.googleadsId, {}, function () {
window.gtag = function gtag() {
window.dataLayer.push(arguments);
};
window.gtag("js", new Date());
if (user.googleadsInitOptions) {
window.gtag("config", user.googleadsId, user.googleadsInitOptions);
}
else {
window.gtag("config", user.googleadsId);
}
if (typeof user.googleadsMore === "function") {
user.googleadsMore();
}
});
},
};
});