Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/latest/custom/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/latest/custom/app.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/latest/custom/e.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/latest/custom/e.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/latest/custom/latest.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Simple Analytics - Privacy-first analytics (docs.simpleanalytics.com/script; 2026-10-15; 5f47; v12) */
/* Simple Analytics - Privacy-first analytics (docs.simpleanalytics.com/script; 2026-10-18; 306e; v12) */
/* eslint-env browser */

(function (
Expand Down Expand Up @@ -765,8 +765,8 @@
if (nav[language]) page[language] = nav[language];
}

// sc = screensizes
if (screen && collectMetricByString("sc")) {
// scre = screensizes
if (screen && collectMetricByString("scre")) {
page.screen_width = screen.width;
page.screen_height = screen.height;
}
Expand Down Expand Up @@ -997,6 +997,9 @@
// Overwrite user defined function
window[eventFunctionName] = defaultEventFunc;

// Automated events wait for this variable, for example ba_event_loaded
window[eventFunctionName + "_loaded"] = trueVar;

// Post events from the queue of the user defined function
for (var event in queue) {
if (hasProp(queue, event)) {
Expand Down
4 changes: 2 additions & 2 deletions dist/latest/custom/latest.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/latest/custom/latest.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/latest/custom/proxy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/latest/custom/proxy.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/latest/hello.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/latest/hello.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/latest/latest.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Simple Analytics - Privacy-first analytics (docs.simpleanalytics.com/script; 2026-10-15; 1a59; v12) */
/* Simple Analytics - Privacy-first analytics (docs.simpleanalytics.com/script; 2026-10-18; 40d9; v12) */
/* eslint-env browser */

(function (
Expand Down Expand Up @@ -765,8 +765,8 @@
if (nav[language]) page[language] = nav[language];
}

// sc = screensizes
if (screen && collectMetricByString("sc")) {
// scre = screensizes
if (screen && collectMetricByString("scre")) {
page.screen_width = screen.width;
page.screen_height = screen.height;
}
Expand Down Expand Up @@ -997,6 +997,9 @@
// Overwrite user defined function
window[eventFunctionName] = defaultEventFunc;

// Automated events wait for this variable, for example ba_event_loaded
window[eventFunctionName + "_loaded"] = trueVar;

// Post events from the queue of the user defined function
for (var event in queue) {
if (hasProp(queue, event)) {
Expand Down
4 changes: 2 additions & 2 deletions dist/latest/latest.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/latest/latest.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/v12/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/v12/app.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/v12/custom/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/v12/custom/app.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/v12/custom/proxy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/v12/custom/proxy.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,9 @@
// Overwrite user defined function
window[eventFunctionName] = defaultEventFunc;

// Automated events wait for this variable, for example ba_event_loaded
window[eventFunctionName + "_loaded"] = trueVar;

// Post events from the queue of the user defined function
for (var event in queue) {
if (hasProp(queue, event)) {
Expand Down
33 changes: 32 additions & 1 deletion test/unit/auto-events.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { expect } = require("chai");
const { createDOM } = require("./helpers/dom-auto-events");
const { createDOM: createTrackerDOM } = require("./helpers/dom");
const { readFileSync } = require("fs");
const { runInNewContext } = require("vm");
const { runInContext, runInNewContext } = require("vm");

function setupDOM() {
const events = [];
Expand Down Expand Up @@ -84,6 +85,36 @@ describe("auto-events", function () {
expect(navigations).to.deep.equal([]);
});

for (const [settings, saGlobal] of [
[{ namespace: "ba" }, "ba_event"],
[{ saGlobal: "my_event" }, "my_event"],
]) {
it(`sends events through the ${saGlobal} tracker function`, function () {
const dom = createTrackerDOM({
settings: { autoCollect: false, ...settings },
});
const script = dom.window.document.createElement("script");
script.src = "auto-events.js";
script.setAttribute("data-sa-global", saGlobal);
dom.window.document.head.appendChild(script);
runInContext(
readFileSync("dist/latest/auto-events.js", "utf8"),
dom.getInternalVMContext()
);
const link = dom.window.document.createElement("a");
link.href = "https://example.org/path";

dom.window.saAutomatedLink(link, "outbound");

expect(
dom.sent.map((request) =>
new URL(request.url).searchParams.get("event")
)
).to.deep.equal(["outbound_example_org"]);
dom.window.close();
});
}

it("tracks outbound link clicks", function (done) {
const dom = setupDOM();
const link = dom.window.document.createElement("a");
Expand Down
Loading