Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

Why data not being passed/captured to eVar on first click event in DTM using custom script?

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi Darius,

Looks like you have a few updates to make to get everything working the way you need in order to capture the information required. I'll number them to make it easier to reference in this forum:

1)

A quick question:
What is your Event Rule type? And what is the CSS Selector you've chosen for this event rule?

I ask because I see that you have a jQuery click listener that you've created in the custom script for the event rule. This shouldn't be necessary. Instead, you could so something like this:

2)

It is against best practices to set Analytics variables in the custom script section of rules in DTM. Instead, set the value into a Data Element, then populate the eVar into the Data Element in the Adobe Analytics accordion within the rule:

 

3)

I also tweaked the code you were using for the custom script section of the rule. I made an assumption here or there, so I'd suggest reviewing and testing it significantly, since I did not inspect your website.

var mbsItem = $(this).parents('.mbs-item'); if (mbsItem.length) { // Do something here _satelite.setVar('localMB',(mbsItem.attr('data-mb-name') + ", " + mbsItem.attr('data-mb-id'))); _satellite.notify('localMB: '+_satellite.getVar('localMB')); return true; } else { // Don't fire the rule return false; }

 

I hope that helps! Let me know if you have questions. I highly recommend going through some of the great videos on Event Based Rules and Data Elements within the Help section: http://www.adobe.com/go/dtm_get_started_en

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

Hi Darius,

Looks like you have a few updates to make to get everything working the way you need in order to capture the information required. I'll number them to make it easier to reference in this forum:

1)

A quick question:
What is your Event Rule type? And what is the CSS Selector you've chosen for this event rule?

I ask because I see that you have a jQuery click listener that you've created in the custom script for the event rule. This shouldn't be necessary. Instead, you could so something like this:

2)

It is against best practices to set Analytics variables in the custom script section of rules in DTM. Instead, set the value into a Data Element, then populate the eVar into the Data Element in the Adobe Analytics accordion within the rule:

 

3)

I also tweaked the code you were using for the custom script section of the rule. I made an assumption here or there, so I'd suggest reviewing and testing it significantly, since I did not inspect your website.

var mbsItem = $(this).parents('.mbs-item'); if (mbsItem.length) { // Do something here _satelite.setVar('localMB',(mbsItem.attr('data-mb-name') + ", " + mbsItem.attr('data-mb-id'))); _satellite.notify('localMB: '+_satellite.getVar('localMB')); return true; } else { // Don't fire the rule return false; }

 

I hope that helps! Let me know if you have questions. I highly recommend going through some of the great videos on Event Based Rules and Data Elements within the Help section: http://www.adobe.com/go/dtm_get_started_en