How to catch click events within topic posting form with jquery?


#1

I’m trying to integrate discourse into our existing gamification system for our main site. (We’re using captainup which is based on an event-driven point system)

I can catch the New Topic click just fine, but can’t catch any of the click events within the topic form popup (the main one I want being the Create Topic button)

I know this is due to ember, which I’m new to - any tips?


Add onClick event to +Create Topic
Google Analytics Event Tracking
How to catch click events on a link in order to fire a pixel
(Simon Cossar) #2

Clicking the ‘Create Topic’ or the ‘Reply’ button from within the composer calls the ‘save’ action in the composer controller. You could override the save action with something like this as custom javascript:

<script>
  var ComposerController = require('discourse/controllers/composer').default;
  
  ComposerController.reopen({
      actions: {
          save: function() {
              // Do what you want here, for example:
              console.log("Creating New Topic?", this.get('model.creatingTopic');
              // Call super to save the topic
              this._super();
          }
      }
  })
</script>

How to catch click events on a link in order to fire a pixel
#4

That worked! Thank you @simon_cossar.


(Alon Levi) #5

Hi @Simon_Cossar, any option to use this kind of code to capture clicks on links/or buttons?
I need to fire a pixel to Google Adwords when a user clicks a link.
Thanks :slight_smile: