diff --git a/lib/plausible_web/plugs/tracker.ex b/lib/plausible_web/plugs/tracker.ex index e64e631d6..05049b453 100644 --- a/lib/plausible_web/plugs/tracker.ex +++ b/lib/plausible_web/plugs/tracker.ex @@ -9,7 +9,8 @@ defmodule PlausibleWeb.Tracker do "compat", "local", "manual", - "file-downloads" + "file-downloads", + "dimensions" ] base_filenames = ["plausible", "script"] diff --git a/lib/plausible_web/templates/layout/_tracking.html.eex b/lib/plausible_web/templates/layout/_tracking.html.eex index 6993d50e4..a73747d81 100644 --- a/lib/plausible_web/templates/layout/_tracking.html.eex +++ b/lib/plausible_web/templates/layout/_tracking.html.eex @@ -1,17 +1,11 @@ <%= if !Application.get_env(:plausible, :is_selfhost) && !@conn.assigns[:skip_plausible_tracking] do %> <%= if Application.get_env(:plausible, :environment) in ["prod", "staging"] do %> - + - <% end %> <%= if Application.get_env(:plausible, :environment) == "dev" do %> - + - <% end %> <% end %> diff --git a/priv/tracker/js/analytics.js b/priv/tracker/js/analytics.js index 54394c7c6..dde9e4a8a 100644 --- a/priv/tracker/js/analytics.js +++ b/priv/tracker/js/analytics.js @@ -1 +1 @@ -!function(){"use strict";var a=window.location,r=window.document,o=r.currentScript,s=o.getAttribute("data-api")||new URL(o.src).origin+"/api/event";function l(t){console.warn("Ignoring Event: "+t)}function t(t,e){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(a.hostname)||"file:"===a.protocol)return l("localhost");if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"===window.localStorage.plausible_ignore)return l("localStorage flag")}catch(t){}var i={};i.n=t,i.u=a.href,i.d=o.getAttribute("data-domain"),i.r=r.referrer||null,i.w=window.innerWidth,e&&e.meta&&(i.m=JSON.stringify(e.meta)),e&&e.props&&(i.p=JSON.stringify(e.props));var n=new XMLHttpRequest;n.open("POST",s,!0),n.setRequestHeader("Content-Type","text/plain"),n.send(JSON.stringify(i)),n.onreadystatechange=function(){4===n.readyState&&e&&e.callback&&e.callback()}}}var e=window.plausible&&window.plausible.q||[];window.plausible=t;for(var i,n=0;n a.length > 0).map(a => a.sort()); compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/plausible.js')) diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js index 12c9e2c11..acbe2ae7c 100644 --- a/tracker/src/plausible.js +++ b/tracker/src/plausible.js @@ -65,8 +65,25 @@ payload.m = JSON.stringify(options.meta) } if (options && options.props) { - payload.p = JSON.stringify(options.props) + payload.p = options.props } + + {{#if dimensions}} + var dimensionAttributes = scriptEl.getAttributeNames().filter(function (name) { + return name.substring(0, 6) === 'event-' + }) + + var props = payload.p || {} + + dimensionAttributes.forEach(function(attribute) { + var propKey = attribute.replace('event-', '') + var propValue = scriptEl.getAttribute(attribute) + props[propKey] = props[propKey] || propValue + }) + + payload.p = props + {{/if}} + {{#if hash}} payload.h = 1 {{/if}}