wrap everything in onPageChange
1. theme settings are only exposed to text/discourse-plugin 2. text/discourse-plugin won't execute automatically
This commit is contained in:
parent
980416d6d7
commit
bf3b766146
@ -1,11 +0,0 @@
|
|||||||
<script type="text/discourse-plugin" version="0.8">
|
|
||||||
window._paq = window._paq || [];
|
|
||||||
window._paq.push(["enableLinkTracking"]);
|
|
||||||
(function() {
|
|
||||||
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://" + settings.host_url;
|
|
||||||
window._paq.push(["setTrackerUrl", u+"piwik.php"]);
|
|
||||||
window._paq.push(["setSiteId", settings.website_id]);
|
|
||||||
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
|
|
||||||
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
|
|
||||||
})();
|
|
||||||
</script>
|
|
@ -1,11 +1,22 @@
|
|||||||
<script type="text/discourse-plugin" version="0.2">
|
<script type="text/discourse-plugin" version="0.2">
|
||||||
api.onPageChange((url, title) => {
|
api.onPageChange((url, title) => {
|
||||||
if (window._paq) {
|
window._paq = window._paq || [];
|
||||||
const currentUser = api._currentUser;
|
window._paq_loaded = window._paq_loaded || false;
|
||||||
window._paq.push(['setCustomVariable', 1, 'Anonymous', !currentUser, 'visit']);
|
|
||||||
window._paq.push(["setCustomUrl", url]);
|
if (!_paq_loaded) {
|
||||||
window._paq.push(["setDocumentTitle", title]);
|
var u = `//${settings.host_url}/`;
|
||||||
window._paq.push(["trackPageView"]);
|
_paq.push(['setTrackerUrl', u+'piwik.php']);
|
||||||
|
_paq.push(['setSiteId', settings.website_id]);
|
||||||
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||||
|
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
||||||
|
_paq_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentUser = api._currentUser;
|
||||||
|
_paq.push(['setCustomVariable', 1, 'Anonymous', !currentUser, 'visit']);
|
||||||
|
_paq.push(["setCustomUrl", url]);
|
||||||
|
_paq.push(["setDocumentTitle", title]);
|
||||||
|
_paq.push(["trackPageView"]);
|
||||||
|
_paq.push(['enableLinkTracking']);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user