Highlighted

In an extensions, I want to code a javascript to track the event for an Social Network button.

Silver Contributor
Silver Contributor

I want to write a javascript in extension that will track which Social Network button (facebook, twitter, instagram) have I clicked. Currently, all the Social buttons have the same class name (hence I could not use jQuery Selector from WebCompanion to capture which Social button is clicked).

Also, In the coding, the Social buton have be coded in <a href> and <img alt>.

 

Please help to understand how can I write an javascript to track the social network button. Thank you.

2 REPLIES 2
Highlighted

In an extensions, I want to code a javascript to track the event for an Social Network button.

Employee Emeritus

Hi prathamesa_thak,

 

If your class name is the same and you are unable to add a unique ID, perhaps you can track the button by its inner text assuming that this is unique for each of the social media buttons.  

 

For example, say your HTML anchor code for the Facebook button looks like this:

 

 

<a href="www.facebook.com/examplePage" class="socialmedia">Facebook Page</a>

 

 

Then you jQuery onHandler can look something like this:

 

 

jQuery(document.body).on('mousedown', 'a.socialmedia:contains("Facebook")', function(e) {
  utag.link({
    event_type: 'social_media_click'
  });
});

 

 

Is this what you are trying to accomplish?

Highlighted

In an extensions, I want to code a javascript to track the event for an Social Network button.

Silver Contributor
Silver Contributor

Hello Menf_Lim, Thank you for your reply.

Let me check and get back to you

 

Appreciate your reply.