Click Event value in evar | Community
Skip to main content
New Member
October 11, 2022
Solved

Click Event value in evar

  • October 11, 2022
  • 1 reply
  • 2943 views

Hello Team,

 

I am trying to get a click event value in evar using Adobe Launch but somehow it's not working. My problem statment is:

We have some videos over our page and every video has a "data-id" value assign to it. I want to assign this custom value in an evar on the click of the play button. I have created a rule which is firing when I am clicking over video button but my evar is not getting any value or even firing.

I added the code to get "data-id" in a data element custom code and assigning that data element to evar using set variables for Adobe Analytics, but somehow it is not working. When I try the data element code in browser console it works correctly.

 

How can I get the custom values in my evar on click?

 

Rule Click Event:

Rule Action:

Data Element:

Data Element Custom Code:

 

$( ".grp-video__play-button" ).click(function() { var id = $(this).parent().parent().parent().attr('data-id'); return id; });

 

 

Video HTML:

 

<div class="grp-yt-video" data-component-name="ytvideo" data-id="ABCDEFGHHIJ" data-start-muted="0" id="grp-video-1796119669" data-initialized="true"> <div class="grp-yt-video__container"> <div data-cmp-is="image" data-cmp-lazy="true" data-cmp-src="/content/grpw/websites/abcd/dummy/1658930331134.jpeg" data-cmp-widths="320, 640, 1280, 2560" class="grp-yt-video__thumbnail cmp-image"> <img src="/de/de/dummy/_jcr_content/par/layoutcontainercontent/columncontrol_1133979323/columncontrolparsys/stack/stackparsys/img.jpeg/1651230331134.jpeg" class="cmp-image__image grp-yt-video__thumbnail-img" data-cmp-hook-image="image" alt="Dummy Text"> <div class="grp-video__play-button"></div> <div class="grp-video__player" style="height: 479.25px;"><iframe class="grp-video__player-iframe" title="video" id="yt-player-0type=" text="" html"="" frameborder="0" src="https://www.youtube-nocookie.com/embed/ABCDEFGHIJHK?mute=0&amp;rel=0"></iframe></div> <div class="grp-video-player-disclaimer" style="display: none;"> <div class="grp-video-player-disclaimer-textbox"> <span class="grp-video-player-disclaimer-text"> Dummy cookie text . </span> <ul class="grp-video-player-disclaimer-linklist"> <li> <a class=" grp-link-list__item " href="#"> Cookies accept und Video </a> </li> </ul> </div> </div> </div> </div> </div>

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by tim_funk

Your Data Element Custom Code isn't setting the value. When doing custom code - its to return a value. And your code is just returning the result of click() - which is just a jQuery object. Not the result of the event firing.

 

My preferred approach is to add a custom condition on the rule that sets VideoID for you and returns true. Something like this:

 

_satellite.setVar('VideoID', this.getAttribute('data-id'))
return true

1 reply

tim_funk
tim_funkAccepted solution
October 11, 2022

Your Data Element Custom Code isn't setting the value. When doing custom code - its to return a value. And your code is just returning the result of click() - which is just a jQuery object. Not the result of the event firing.

 

My preferred approach is to add a custom condition on the rule that sets VideoID for you and returns true. Something like this:

 

_satellite.setVar('VideoID', this.getAttribute('data-id'))
return true
Harsh61Author
New Member
October 11, 2022

I added the above condition in rule, and my rule is still firing but still my evar is empty.

Do I need to do some change in data element code also?

tim_funk
October 11, 2022

Ok, I tried like below screenshot in condition

and set my evar as same before in setVariables.

but it didn't work, my evar still comes empty

Did I use ('data-id') correctly?


In jQuery if you use data() - You need to drop "data-" from the argument.

But if you said .attr("data-id") - that shoudl work