FEATURE: trigger app event for click tracking (#25381)
* FEATURE: trigger app event for click tracking * fix the build
This commit is contained in:
parent
eff485e4c0
commit
fdf332f3aa
|
@ -1,3 +1,4 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import Component from "@ember/component";
|
||||
import { alias } from "@ember/object/computed";
|
||||
import { schedule, scheduleOnce, throttle } from "@ember/runloop";
|
||||
|
@ -105,7 +106,7 @@ export default Component.extend(
|
|||
$(this.element).on(
|
||||
"click.discourse-redirect",
|
||||
".cooked a, a.track-link",
|
||||
(e) => ClickTrack.trackClick(e, this.siteSettings)
|
||||
(e) => ClickTrack.trackClick(e, getOwner(this))
|
||||
);
|
||||
this.appEvents.on("discourse:focus-changed", this, "gotFocus");
|
||||
this.appEvents.on("post:highlight", this, "_highlightPost");
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import Component from "@ember/component";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
export default Component.extend({
|
||||
click(event) {
|
||||
if (event?.target?.tagName === "A") {
|
||||
return ClickTrack.trackClick(event, this.siteSettings);
|
||||
return ClickTrack.trackClick(event, getOwner(this));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import Component from "@ember/component";
|
||||
import { on } from "@ember/object/evented";
|
||||
import { later } from "@ember/runloop";
|
||||
|
@ -39,7 +40,7 @@ export default Component.extend(LoadMore, {
|
|||
() => false
|
||||
);
|
||||
$(this.element).on("click.discourse-redirect", ".excerpt a", (e) => {
|
||||
return ClickTrack.trackClick(e, this.siteSettings);
|
||||
return ClickTrack.trackClick(e, getOwner(this));
|
||||
});
|
||||
this._updateLastDecoratedElement();
|
||||
this.appEvents.trigger("decorate-non-stream-cooked-element", this.element);
|
||||
|
|
|
@ -73,7 +73,7 @@ export function openLinkInNewTab(event, link) {
|
|||
}
|
||||
|
||||
export default {
|
||||
trackClick(e, siteSettings, { returnPromise = false } = {}) {
|
||||
trackClick(e, owner, { returnPromise = false } = {}) {
|
||||
// right clicks are not tracked
|
||||
if (e.which === 3) {
|
||||
return true;
|
||||
|
@ -95,11 +95,13 @@ export default {
|
|||
if (!href || href.startsWith("mailto:")) {
|
||||
return true;
|
||||
}
|
||||
owner?.lookup("service:app-events").trigger("click-tracked", href);
|
||||
|
||||
if (link.classList.contains("attachment")) {
|
||||
// Warn the user if they cannot download the file.
|
||||
if (
|
||||
siteSettings?.prevent_anons_from_downloading_files &&
|
||||
owner?.lookup("service:site-settings")
|
||||
?.prevent_anons_from_downloading_files &&
|
||||
!User.current()
|
||||
) {
|
||||
const dialog = getOwnerWithFallback(this).lookup("service:dialog");
|
||||
|
|
Loading…
Reference in New Issue