diff --git a/components/forms/TrackingCodeForm.js b/components/forms/TrackingCodeForm.js
index 9e8e81e2..61df1275 100644
--- a/components/forms/TrackingCodeForm.js
+++ b/components/forms/TrackingCodeForm.js
@@ -17,21 +17,19 @@ export default function TrackingCodeForm({ values, onClose }) {
/>
- {/* Run `npm run build-snippet, and copy paste here the content of public/snippet.js */}
- {/* TODO: use webpack importing function to import the content of the file here ? */}
-
+
diff --git a/tracker/index.js b/tracker/index.js
index 2cbc3ce2..28b8dfca 100644
--- a/tracker/index.js
+++ b/tracker/index.js
@@ -43,7 +43,7 @@ import { removeTrailingSlash } from '../lib/url';
element.className.split(' ').forEach(className => {
if (/^umami--([a-z]+)--([a-z0-9_]+[a-z0-9-_]+)$/.test(className)) {
const [, type, value] = className.split('--');
- const listener = () => event(type, value);
+ const listener = () => collectEvent(type, value);
listeners.push([element, type, listener]);
element.addEventListener(type, listener, true);
@@ -94,7 +94,7 @@ import { removeTrailingSlash } from '../lib/url';
pageViewWithAutoEvents(currentUrl, currentRef);
};
- const event = (event_type, event_value, url = currentUrl, uuid = website) => collect('event', {
+ const collectEvent = (event_type, event_value, url = currentUrl, uuid = website) => collect('event', {
url,
event_type,
event_value,
@@ -107,17 +107,20 @@ import { removeTrailingSlash } from '../lib/url';
};
+ const umamiFunctions = { collect, pageView, collectEvent, registerAutoEvents };
const scheduledCalls = window.umami.calls;
- window.umami = {
- collect,
- pageView,
- event,
- registerAutoEvents
- };
- scheduledCalls.forEach(([fnName, ...params]) => {
- window.umami[fnName].apply(window.umami, params);
+
+ window.umami = event_value => collect('event', { event_type: 'custom', event_value });
+ Object.keys(umamiFunctions).forEach((key) => {
+ window.umami[key] = umamiFunctions[key];
});
+ if (scheduledCalls) {
+ scheduledCalls.forEach(([fnName, ...params]) => {
+ window.umami[fnName].apply(window.umami, params);
+ });
+ }
+
/* Start */
if (!skipAuto) {
registerAutoEvents().catch(e => console.error(e));
diff --git a/tracker/snippet.js b/tracker/snippet.js
index 89a3a865..df1a8eb5 100644
--- a/tracker/snippet.js
+++ b/tracker/snippet.js
@@ -33,7 +33,11 @@
otherScript.parentNode.insertBefore(scriptElement, otherScript);
};
- umami.load('${document.location.origin}/umami.js', '${values.website_uuid}', false);
+ umami.load('[HOST]/umami.js', '[UMAMI_UUID]', false);
}
}
-})(window);
\ No newline at end of file
+})(window);
+// This snippet is for more advanced use case of Umami. If you want to track custom events,
+// and not worry about having blocking script in the header,
+// use this snippet (compiled version available in /public/snippet.js).
+// Just remember to replace [HOST] and [UMAMI_UUID] when pasting it.
\ No newline at end of file