Skip to content

Commit

Permalink
[#257] Initial implementation of piwik analytic
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 24, 2024
1 parent 0c1e426 commit 2b6de1b
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,100 @@
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script src="%PUBLIC_URL%/config.js"></script>

<!-- PIWIK -->
<script type="text/javascript">
const origin = window?.location?.origin;
const ID =
origin?.includes("test") && origin?.includes("localhost")
? "418c8745-6f9d-4e93-946c-ef65731f366d"
: "418c8745-6f9d-4e93-946c-ef65731f366d";
(function (window, document, dataLayerName, id) {
(window[dataLayerName] = window[dataLayerName] || []),
window[dataLayerName].push({
start: new Date().getTime(),
event: "stg.start",
});
var scripts = document.getElementsByTagName("script")[0],
tags = document.createElement("script");
function stgCreateCookie(a, b, c) {
var d = "";
if (c) {
var e = new Date();
e.setTime(e.getTime() + 24 * c * 60 * 60 * 1e3),
(d = "; expires=" + e.toUTCString());
}
document.cookie = a + "=" + b + d + "; path=/";
}
var isStgDebug =
(window.location.href.match("stg_debug") ||
document.cookie.match("stg_debug")) &&
!window.location.href.match("stg_disable_debug");
stgCreateCookie("stg_debug", isStgDebug ? 1 : "", isStgDebug ? 14 : -1);
var qP = [];
dataLayerName !== "dataLayer" &&
qP.push("data_layer_name=" + dataLayerName),
isStgDebug && qP.push("stg_debug");
var qPString = qP.length > 0 ? "?" + qP.join("&") : "";
(tags.async = !0),
(tags.src =
"//analytics.akvo.org/containers/" + id + ".js" + qPString),
scripts.parentNode.insertBefore(tags, scripts);
!(function (a, n, i) {
a[n] = a[n] || {};
for (var c = 0; c < i.length; c++)
!(function (i) {
(a[n][i] = a[n][i] || {}),
(a[n][i].api =
a[n][i].api ||
function () {
var a = [].slice.call(arguments, 0);
"string" == typeof a[0] &&
window[dataLayerName].push({
event: n + "." + i + ":" + a[0],
parameters: [].slice.call(arguments, 1),
});
});
})(i[c]);
})(window, "ppms", ["tm", "cm"]);
})(window, document, "dataLayer", ID);
</script>
<noscript
><iframe
src="//analytics.akvo.org/containers/ID/noscript.html"
height="0"
width="0"
style="display: none; visibility: hidden"
></iframe
></noscript>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
const origin = window?.location?.origin;
const ID =
origin?.includes("test") && origin?.includes("localhost")
? "418c8745-6f9d-4e93-946c-ef65731f366d"
: "418c8745-6f9d-4e93-946c-ef65731f366d";
// Get the noscript element
var noscriptElement = document.querySelector("noscript");
// Check if the noscript element exists
if (noscriptElement) {
// Extract the current src attribute
var currentSrc = noscriptElement.innerHTML.match(/src="([^"]+)"/);
// Check if the src attribute is found
if (currentSrc) {
// Replace the old ID with the new ID
var newSrc = currentSrc[1].replace(
"/containers/ID/",
`/containers/${ID}/`
);
// Update the src attribute
noscriptElement.innerHTML = noscriptElement.innerHTML.replace(
currentSrc[1],
newSrc
);
}
}
});
</script>
</body>
</html>

0 comments on commit 2b6de1b

Please # to comment.