Why data not being passed/captured to eVar on first click event in DTM using custom script?
I wrote a couple of script, one I use as a custom script directly within the Event Rule, the other is in a data element. In either case when the click event occurs the data is not passed to eVar the first time, but If I click it 2 more times the data gets passed. It's as if the first time sets the script to run, the second time captures the data, and the 3rd time populates the eVar within DTM Switch. It could be that the new page gets fired too fast so I don't see anything on the second click. Anyways.. I want it to capture the data on the first click. I am including both script below. The first one is the one I am using directly in the Event Rule.. The second one is in the data element. Basically I just tried two different ways to capture the data when the button is clicked. I will use only one once I get one of them to work correctly.
If you want to take a look at the page to see how it is set up.. please go to http://atlanticbay.com/search-mortgage-bankers/.
The CTA is the View Me button under each of the Mortgage Bankers.
the HTML Element looks like this.
<div class="col-lg-4 col-md-6 col-sm-6 mb-col-0 mbs-item" data-mb-id="26982" data-mb-name="Victoria Anderson" data-mb-fname="Victoria" data-mb-lname="Anderson" data-mb-city="Charlotte" data-mb-state="NC" data-mb-zip="28777"><div class="mbs-item-inner"> <div class="mb-img"><img src="http://d3k0pmp8tgrvhb.cloudfront.net/wp-content/uploads/20160906115020/victoria-anderson-hero.jpg" alt="Victoria Anderson - Mortgage Banker" class="img-responsive mb-profile-img"> </div><h5 class="mb-name">Victoria Anderson</h5><p class="mb-title">Mortgage Banker</p> <p class="mb-loc">Charlotte, NC</p><p class="mb-view"> <a href="http://atlanticbay.com/victoriaanderson/" class="btn-ghost-blue" target="_blank">VIEW ME</a></p><p class="mb-apply"><a href="https://www.secureloandocs.com/app/36309094/loId/23500" class="btn-ghost-blue" target="_blank">APPLY NOW!</a></p></div></div>
The custom script in the Event rule
$('.mb-view a').click(function() { var mbsItem = $(this).parents('.mbs-item'); if (mbsItem.length) { // Do something here s.eVar51 = (mbsItem.attr('data-mb-name') + ", " + mbsItem.attr('data-mb-id')); console.log(s.eVar51); } else { // Don't follow the link return false; } });The script in the Data element. I tried to capture the href in this script, because I couldn't figure out how to use the script above within a data element.
$(this).InnerText= "view Me"; //var name =$(this).href; _satellite.getVar($(this).href); return true;
Oh by the way, please do not get so caught up on the syntax or the why I wrote the script the way that I did. I am learning on the fly, and do not have access to a developer. You can make comments on it, but please stay focused on resolving the issue.
Thank you
Darius


