mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
Reverted tracker to old behaviour while still keeping more advanced use case
This commit is contained in:
parent
348ee22e18
commit
09235ddacf
@ -17,21 +17,19 @@ export default function TrackingCodeForm({ values, onClose }) {
|
|||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
<FormRow>
|
<FormRow>
|
||||||
{/* 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 ? */}
|
|
||||||
<textarea
|
<textarea
|
||||||
ref={ref}
|
ref={ref}
|
||||||
rows={3}
|
rows={3}
|
||||||
cols={60}
|
cols={60}
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
defaultValue={`!function(){"use strict";!function(e){var t=e.umami=e.umami||[];if(!t.registerAutoEvents)if(t.invoked)e.console&&console.error&&console.error("Umami snippet included twice.");else{t.invoked=!0,t.calls=[],t.methods=["registerAutoEvents","event","pageView"],t.factory=function(e){return function(){var r=Array.prototype.slice.call(arguments);return r.unshift(e),t.calls.push(r),t}};for(var r=0;r<t.methods.length;r++){var i=t.methods[r];t[i]=t.factory(i)}t.load=function(e,t,r){var i=document.createElement("script");i.type="text/javascript",i.defer=!0,i.async=!0,i.setAttribute("data-website-id",t),r&&i.setAttribute("data-skip-auto","true"),i.src=e;var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(i,o)},t.load("${document.location.origin}/umami.js","${values.website_uuid}",!1)}}(window)}();`}
|
defaultValue={`<script async defer data-website-id="${values.website_uuid}" src="${document.location.origin}/umami.js"></script>`}
|
||||||
readOnly
|
readOnly
|
||||||
/>
|
/>
|
||||||
</FormRow>
|
</FormRow>
|
||||||
<FormButtons>
|
<FormButtons>
|
||||||
<CopyButton type="submit" variant="action" element={ref} />
|
<CopyButton type="submit" variant="action" element={ref}/>
|
||||||
<Button onClick={onClose}>
|
<Button onClick={onClose}>
|
||||||
<FormattedMessage id="button.cancel" defaultMessage="Cancel" />
|
<FormattedMessage id="button.cancel" defaultMessage="Cancel"/>
|
||||||
</Button>
|
</Button>
|
||||||
</FormButtons>
|
</FormButtons>
|
||||||
</FormLayout>
|
</FormLayout>
|
||||||
|
@ -43,7 +43,7 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
element.className.split(' ').forEach(className => {
|
element.className.split(' ').forEach(className => {
|
||||||
if (/^umami--([a-z]+)--([a-z0-9_]+[a-z0-9-_]+)$/.test(className)) {
|
if (/^umami--([a-z]+)--([a-z0-9_]+[a-z0-9-_]+)$/.test(className)) {
|
||||||
const [, type, value] = className.split('--');
|
const [, type, value] = className.split('--');
|
||||||
const listener = () => event(type, value);
|
const listener = () => collectEvent(type, value);
|
||||||
|
|
||||||
listeners.push([element, type, listener]);
|
listeners.push([element, type, listener]);
|
||||||
element.addEventListener(type, listener, true);
|
element.addEventListener(type, listener, true);
|
||||||
@ -94,7 +94,7 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
pageViewWithAutoEvents(currentUrl, currentRef);
|
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,
|
url,
|
||||||
event_type,
|
event_type,
|
||||||
event_value,
|
event_value,
|
||||||
@ -107,17 +107,20 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const umamiFunctions = { collect, pageView, collectEvent, registerAutoEvents };
|
||||||
const scheduledCalls = window.umami.calls;
|
const scheduledCalls = window.umami.calls;
|
||||||
window.umami = {
|
|
||||||
collect,
|
window.umami = event_value => collect('event', { event_type: 'custom', event_value });
|
||||||
pageView,
|
Object.keys(umamiFunctions).forEach((key) => {
|
||||||
event,
|
window.umami[key] = umamiFunctions[key];
|
||||||
registerAutoEvents
|
|
||||||
};
|
|
||||||
scheduledCalls.forEach(([fnName, ...params]) => {
|
|
||||||
window.umami[fnName].apply(window.umami, params);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (scheduledCalls) {
|
||||||
|
scheduledCalls.forEach(([fnName, ...params]) => {
|
||||||
|
window.umami[fnName].apply(window.umami, params);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/* Start */
|
/* Start */
|
||||||
if (!skipAuto) {
|
if (!skipAuto) {
|
||||||
registerAutoEvents().catch(e => console.error(e));
|
registerAutoEvents().catch(e => console.error(e));
|
||||||
|
@ -33,7 +33,11 @@
|
|||||||
otherScript.parentNode.insertBefore(scriptElement, otherScript);
|
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);
|
})(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.
|
Loading…
Reference in New Issue
Block a user