aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-02-24 13:49:57 +0100
committerArmand Philippot <git@armandphilippot.com>2022-02-24 13:49:57 +0100
commit204a0c7b9665e3f85b3839a3007c1063bd436e77 (patch)
treed421b89fc268b3da5c4dd2b8098a34c4466ee209 /src/js
parent137c36a5e65cae30e08edd49d25a831b6d996944 (diff)
chore: set up Ackee
Diffstat (limited to 'src/js')
-rw-r--r--src/js/app.js6
-rw-r--r--src/js/utilities/ackee.js42
2 files changed, 47 insertions, 1 deletions
diff --git a/src/js/app.js b/src/js/app.js
index 48e3725..df6eff4 100644
--- a/src/js/app.js
+++ b/src/js/app.js
@@ -5,6 +5,7 @@ import {
currentLocale,
supportedLanguages,
} from './i18n/i18n';
+import { createAckeeInstance, setAckeeRecord } from './utilities/ackee';
import {
hideToBottom,
hideToLeft,
@@ -360,9 +361,12 @@ function setAppLocale() {
}
/**
- * Initialize the website with the projects list.
+ * Initialize the website with the projects list and Ackee.
*/
function init() {
+ const ackee = createAckeeInstance();
+
+ setAckeeRecord(ackee);
setAppLocale();
translateHTMLContent();
replaceLegalNoticeLink();
diff --git a/src/js/utilities/ackee.js b/src/js/utilities/ackee.js
new file mode 100644
index 0000000..8584e2e
--- /dev/null
+++ b/src/js/utilities/ackee.js
@@ -0,0 +1,42 @@
+import * as ackeeTracker from 'ackee-tracker';
+
+/**
+ * Retrieve the Ackee website.
+ * @returns {string} The ackee website.
+ */
+function getAckeeDomain() {
+ return `https://${process.env.ACKEE_DOMAIN}`;
+}
+
+/**
+ * Retrieve the domain Id.
+ * @returns {string} The domain Id configured in Ackee settings.
+ */
+function getAckeeSiteId() {
+ return process.env.ACKEE_SITE_ID;
+}
+
+/**
+ * Create a new Ackee instance.
+ * @returns An Ackee instance.
+ */
+function createAckeeInstance() {
+ const domain = getAckeeDomain();
+
+ return ackeeTracker.create(domain, {
+ detailed: true,
+ ignoreLocalhost: true,
+ ignoreOwnVisits: true,
+ });
+}
+
+/**
+ * Create or update an Ackee record.
+ * @param {*} instance An Ackee Instance
+ */
+function setAckeeRecord(instance) {
+ const siteId = getAckeeSiteId();
+ instance.record(siteId);
+}
+
+export { createAckeeInstance, setAckeeRecord };