Populate Data Element With Clicked Element

Avatar

Avatar

alim92960278

Avatar

alim92960278

alim92960278

06-11-2015

Our website has eight links to social media. Currently, I have a separate event rule for each of these. Values are manually assigned: prop23="Facebook"

This is kind of stupid!

I want to create an event rule that will populate prop23 with part of the alt tag

alt="Facebook Logo" would become prop23="Facebook"

I have added this code as a Custom Rule Condition:

var linkName = this.getAttribute('alt');
_satellite.notify("Result: "+linkName,1);
var social= linkName.substring(0,8);
_satellite.notify("Result2: "+social,1);
return true;

 

It returns:

"SATELLITE: Result: Facebook Logo"
"SATELLITE: Result2: Facebook"

How can I populate prop23 with the value from my variable named "social"?

Is there a way to set the value of a Data Element in this code?

Thanks,

Ali

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

ParitMittal

Avatar

ParitMittal

ParitMittal

17-11-2015

Hi,

In continuation to the discussion, you can also try an alternate solution for the problem through Event Rule. Please follow the below steps:

  • Create an Event Rule 
  • Select the event type and specify the element tag or selector i.e. name of the tag which you want to track
  • Select appropriate bubbling check box
  • Under the Adobe Analytics  section-   
    • Select the appropriate radio button for tracking  i.e. S.tl() 
    • Select the appropriate  link tracking option i.e. custom link tracking and provide Link Name as social.   
    • In the custom page code editor write the below code                                                                                                      
    • var linkName = this.getAttribute('alt');
      var social= linkName.substring(0,8);
      s.linkTrackVars = 'prop23';
      s.prop23 = social;    

 Please let me know us know if you have any questions 
Thanks
Parit                                                                                                                                                                                                                                                                                                                                                                                                                                    

Answers (3)

Answers (3)

Avatar

Avatar

alim92960278

Avatar

alim92960278

alim92960278

23-11-2015

Thanks Parit. That's perfect!                   

Avatar

Avatar

alim92960278

Avatar

alim92960278

alim92960278

12-11-2015

Thanks for the reply.

The reason I put the code in the event instead of a data element is that I can't get this line to work in a data element:

var linkName = this.getAttribute('alt');

I don't know how to refer to the clicked element in a data element?

Avatar

Avatar

taciac

Avatar

taciac

taciac

10-11-2015

The code that is in the custom code section can be added to a custom script data element. Once it is added when setting up the prop in the rule the data element name will be an option. From there you can test in staging. More information on data elements is available here: https://marketing.adobe.com/resources/help/en_US/dtm/data_elements.html