From afe7429e7d6c0ed42ebccfdfc35eaa9f701b6562 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 7 Oct 2019 16:38:57 -0400 Subject: [PATCH] Add more analytics events The ability to track when likes and bookmarks are toggled --- app/assets/javascripts/discourse/models/post.js.es6 | 5 ++++- app/assets/javascripts/discourse/widgets/post.js.es6 | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/models/post.js.es6 b/app/assets/javascripts/discourse/models/post.js.es6 index 9a9fbe8e635..a82cef491d2 100644 --- a/app/assets/javascripts/discourse/models/post.js.es6 +++ b/app/assets/javascripts/discourse/models/post.js.es6 @@ -316,7 +316,10 @@ const Post = RestModel.extend({ // need to wait to hear back from server (stuff may not be loaded) return Discourse.Post.updateBookmark(this.id, this.bookmarked) - .then(result => this.set("topic.bookmarked", result.topic_bookmarked)) + .then(result => { + this.set("topic.bookmarked", result.topic_bookmarked); + this.appEvents.trigger("page:bookmark-post-toggled", this); + }) .catch(error => { this.toggleProperty("bookmarked"); if (bookmarkedTopic) { diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6 index 65f55a996b1..12eadf99cb1 100644 --- a/app/assets/javascripts/discourse/widgets/post.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post.js.es6 @@ -692,9 +692,10 @@ export default createWidget("post", { const likeAction = post.get("likeAction"); if (likeAction && likeAction.get("canToggle")) { - return likeAction - .togglePromise(post) - .then(result => this._warnIfClose(result)); + return likeAction.togglePromise(post).then(result => { + this.appEvents.trigger("page:like-toggled", post, likeAction); + return this._warnIfClose(result); + }); } },