Skip to content

Commit

Permalink
Default tracking url for pageviews.js
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Jan 16, 2025
1 parent 225339e commit 5ca50f5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions plain-pageviews/plain/pageviews/assets/pageviews/pageviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
}

// Get the tracking URL from the data-track-url attribute
const trackUrl = scriptTag.getAttribute("data-track-url");
let trackUrl = scriptTag.getAttribute("data-track-url");

if (!trackUrl) {
console.error("Missing 'data-track-url' attribute in the <script> tag.");
return;
const defaultTrackPath = "/pageviews/track/";
try {
const scriptUrl = new URL(scriptTag.src);
trackUrl = `${scriptUrl.origin}${defaultTrackPath}`;
} catch (error) {
trackUrl = defaultTrackPath;
}
}

// Function to send a pageview event using the Beacon API
Expand Down

0 comments on commit 5ca50f5

Please sign in to comment.