Add function in SDK to trigger custom events

This commit is contained in:
Uku Taht 2019-10-31 12:08:55 +08:00
parent d687663b80
commit 05911f2a20
3 changed files with 24 additions and 5 deletions

View File

@ -77,13 +77,13 @@
}))
}
function page() {
function trigger(eventName) {
if (/localhost$/.test(window.location.hostname)) return ignore('website is running locally');
if (window.location.protocol === 'file:') return ignore('website is running locally');
if (window.document.visibilityState === 'prerender') return ignore('document is prerendering');
var payload = getUserData()
payload.name = 'pageview'
payload.name = eventName
payload.url = getUrl()
var request = new XMLHttpRequest();
@ -97,6 +97,11 @@
setUserData(payload)
}
}
}
function page() {
trigger('pageview')
}
function trackPushState() {
@ -112,6 +117,7 @@
const functions = {
page: page,
trigger: trigger,
trackPushState: trackPushState
}

View File

@ -77,13 +77,13 @@
}))
}
function page() {
function trigger(eventName) {
if (/localhost$/.test(window.location.hostname)) return ignore('website is running locally');
if (window.location.protocol === 'file:') return ignore('website is running locally');
if (window.document.visibilityState === 'prerender') return ignore('document is prerendering');
var payload = getUserData()
payload.name = 'pageview'
payload.name = eventName
payload.url = getUrl()
var request = new XMLHttpRequest();
@ -97,6 +97,11 @@
setUserData(payload)
}
}
}
function page() {
trigger('pageview')
}
var his = window.history

View File

@ -1,3 +1,11 @@
<%= if Mix.env() == :prod && !@conn.assigns[:skip_plausible_tracking] do %>
<script async defer type="text/javascript" src="https://plausible.io/js/plausible.js"></script>
<script>
(function (w,d,s,o,f,js,fjs) {
w[o] = w[o] || function () { (w[o].q = w[o].q || []).push(arguments) };
js = d.createElement(s), fjs = d.getElementsByTagName(s)[0];
js.id = o; js.src = f; js.async = 1; fjs.parentNode.insertBefore(js, fjs);
}(window, document, 'script', 'plausible', 'https://plausible.io/js/p.js'));
plausible('page')
</script>\
<% end %>