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

**URL:** https://meta.discourse.org/t/how-to-catch-click-events-on-a-link-in-order-to-fire-a-pixel/58704
**Category:** Support
**Created:** [2017年三月9日 08:39 UTC](https://meta.discourse.org/t/how-to-catch-click-events-on-a-link-in-order-to-fire-a-pixel/58704 "2017-03-09T08:39:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![alonle](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@alonle](https://meta.discourse.org/u/alonle)
#### Post date: [2017年三月9日 08:39 UTC](https://meta.discourse.org/t/how-to-catch-click-events-on-a-link-in-order-to-fire-a-pixel/58704/1 "2017-03-09T08:39:06Z")

</div>

Hi [@team](https://meta.discourse.org/groups/team), Is there any way to catch click event on a link and fire a pixel to google adwords.  
I want to know if user click on an amazon link on my site.

I saw this topic  
[https://meta.discourse.org/t/how-to-catch-click-events-within-topic-posting-form-with-jquery/36184](https://meta.discourse.org/t/how-to-catch-click-events-within-topic-posting-form-with-jquery/36184)

Anything similar to this code can be done with a link? (html a href)

> [@simon](#):
>
> \<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\>

Thanks

---

<div class="post-metadata">

### Author: ![joebuhlig](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joebuhlig/32/193054_2.png) [@joebuhlig](https://meta.discourse.org/u/joebuhlig)
#### Post date: [2017年三月9日 12:45 UTC](https://meta.discourse.org/t/how-to-catch-click-events-on-a-link-in-order-to-fire-a-pixel/58704/2 "2017-03-09T12:45:01Z")

</div>

You should be able to catch click events with jquery via a customization. Put this in the `</head>` section:

```javascript
<script type="text/discourse-plugin" version="0.2">
    Discourse.PageTracker.current().on('change', function () {
        $(".topic-list-item .title").on("click", function(){
            console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        })
    })
</script>

```

This will log the string of x`s every time you click on the title of a topic in a list of topics. You could alter this to do whatever you please for every link on the site.

---

<div class="post-metadata">

### Author: ![alonle](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@alonle](https://meta.discourse.org/u/alonle)
#### Post date: [2017年三月12日 13:52 UTC](https://meta.discourse.org/t/how-to-catch-click-events-on-a-link-in-order-to-fire-a-pixel/58704/3 "2017-03-12T13:52:15Z")

</div>

Thanks, it worked, I end up using the api.onPageChange and also add setTimeout since the page changed and not all page was render to set the click binding.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [2017年三月13日 15:38 UTC](https://meta.discourse.org/t/how-to-catch-click-events-on-a-link-in-order-to-fire-a-pixel/58704/4 "2017-03-13T15:38:14Z")

</div>

I should warn you that `setTimeout` is unreliable for knowing when things are rendered. It might work in your testing but there could be times when the timeout fires before things have been rendered.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022年九月15日 19:00 UTC](https://meta.discourse.org/t/how-to-catch-click-events-on-a-link-in-order-to-fire-a-pixel/58704/7 "2022-09-15T19:00:47Z")

</div>


