Rich-text Reply

How do I track clicks on a group of links instead of doing each seperately

michelleb 01-26-16

How do I track clicks on a group of links instead of doing each seperately

I want to track a group of links on my page, I don't care about each one individually but instead just whether or not users are clicking in that section.  Is there a way to track all links at once?

JDahlinANF 01-26-16
 

Re: How do I track clicks on a group of links instead of doing each seperately

[ Edited ]

@michelleb - I presume you are setting up a goal?

If so, when you are creating or editing your click goal, there is a link named "Advanced".

Click "Advanced" and you will see where you can enter the jQuery selectors for this click goal.

This is where you would enter all of the selectors.

If you are unfamiliar with how to list two different selectors as one statement, it may be helpful to provide a link to your site and instructions on which links you want added to your goal and we can write the selector for you.

 

For example,

If your selectors are both 

.link

and

.otherlink

You would add both of them to the "Selector" field as a comma separated list:

.link, .otherlink

 e.g., This goal is for my Add To Bag button which can be accessed by two different selectors:

#primary_content .add-to-bag > .action

and

.product__actions--add-to-bag

 

Capture.PNG

michelleb 01-26-16
 

Re: How do I track clicks on a group of links instead of doing each seperately

The section of links I'm looking to select change depending on the page the user is on, and also on some pages there are 3 links, oher there are 4 etc. so there aren't just a select few links I could add here to be sure I include all of them
robertchan 01-26-16
 

Re: How do I track clicks on a group of links instead of doing each seperately

Hi Michelle,

 

If you have the parameters of the pages where links will be tracked, you could do something like this in the variation code:

  

var optUrl = location.pathname; //gets the url
 
  if(optUrl.indexOf('somethingyourURLcontainsblahblah') > -1) {
    $("p a").attr("class","optLink1"); //would add a class for tracking on links in this page
  }
 
  if(optUrl.indexOf('somethingyourURLcontainsdoodoo') > -1) {
    $("p a").attr("class","optLink2");
  }
 
  if(optUrl.indexOf('somethingyourURLcontainsmushmush') > -1) {
    $("p a").attr("class","optLink3");
  }
});

 

You would need to adjust the $("p a") to wherever your links are located on the page, but essentially this would help you add tracking classes to 3 sets of links on 3 different pages. You would then create a custom click goal in Optimizely and add the classes under the advanced options area (e.g. .optLink3).

 

Robert Chan

Experimentation Hero