Expand my Community achievements bar.

's_objectID' not working on a button element

Avatar

Level 4

Regarding the implementation of the 's_objectID'  as per this page.

 

I can't see to get it to work on a button element. 

Is this designed to be placed on any html element or just an a element link?

 

Thanks.

1 Reply

Avatar

Community Advisor and Adobe Champion

It's probably because Buttons don't trigger Activity Map by default?

 

I had to add some modified code to get it to read buttons.... I don't actually use the s_objectID.. but in theory if you can get the Activity Map to read button elements, this should then work??

 

Unless of course modifying the Activity Map link detection breaks s_objectID....

 

 

Basically, I used
https://experienceleague.adobe.com/docs/analytics/analyze/activity-map/link-tracking/activitymap-lin...

to modify the s.ActivityMap.link

 

The example code is:

// only ever use "title" attributes from A tags
function(clickedElement) {
  var linkId;
  if (clickedElement && clickedElement.tagName.toUpperCase() === 'A') {
    linkId = clickedElement.getAttribute('title');
  }
  return linkId;
}

 

Where you can see that in this case, they are over-writing the linkID with the title attribute, instead of the innerText...

 

In my case, I added a check for 

clickedElement.tagName.toUpperCase() === 'BUTTON'


And created some additional checks for content...

  • pulling from a custom data attribute if it exists
  • then if not, looking at the innerText
  • then if nothing looking there, if the child element was an image and pulling the alt text of the image
  • then if that failed pulling from the title attribute
  • then if still nothing pulling from the id
  • then finally failing all of that, pulling from the class

 

 

Basically, as I discovered different variants on our sites that didn't get a linkId (meaning Activity Map didn't track them) I added variations to check... most of out links fall into the first three items... I rarely see the other logic, but I left it in place to be safe.....