Use Discourse.getURL for /clicks/track so clicks can be tracked on relative URLs (#8079)

Use Discourse.getURL for /clicks/track so clicks can be tracked on relative URLs (#8079)

diff --git a/app/assets/javascripts/discourse/lib/ajax.js.es6 b/app/assets/javascripts/discourse/lib/ajax.js.es6
index 1cec514..cafa6e6 100644
--- a/app/assets/javascripts/discourse/lib/ajax.js.es6
+++ b/app/assets/javascripts/discourse/lib/ajax.js.es6
@@ -159,7 +159,7 @@ export function ajax() {
   if (
     args.type &&
     args.type.toUpperCase() !== "GET" &&
-    url !== "/clicks/track" &&
+    url !== Discourse.getURL("/clicks/track") &&
     !Discourse.Session.currentProp("csrfToken")
   ) {
     promise = new Ember.RSVP.Promise((resolve, reject) => {
diff --git a/app/assets/javascripts/discourse/lib/click-track.js.es6 b/app/assets/javascripts/discourse/lib/click-track.js.es6
index 438915c..42a6562 100644
--- a/app/assets/javascripts/discourse/lib/click-track.js.es6
+++ b/app/assets/javascripts/discourse/lib/click-track.js.es6
@@ -102,9 +102,9 @@ export default {
         data.append("url", href);
         data.append("post_id", postId);
         data.append("topic_id", topicId);
-        navigator.sendBeacon("/clicks/track", data);
+        navigator.sendBeacon(Discourse.getURL("/clicks/track"), data);
       } else {
-        trackPromise = ajax("/clicks/track", {
+        trackPromise = ajax(Discourse.getURL("/clicks/track"), {
           type: "POST",
           data: {
             url: href,

GitHub sha: 530356f4

1 Like