mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 11:12:15 +03:00
Add function in SDK to trigger custom events
This commit is contained in:
parent
d687663b80
commit
05911f2a20
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 %>
|
||||
|
Loading…
Reference in New Issue
Block a user