Populate Data Element With Clicked Element | Community
Skip to main content
AliMaleki
Level 4
November 6, 2015
Solved

Populate Data Element With Clicked Element

  • November 6, 2015
  • 4 replies
  • 2986 views

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

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 ParitMittal

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                                                                                                                                                                                                                                                                                                                                                                                                                                    

4 replies

taciac
Level 9
November 10, 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

AliMaleki
AliMalekiAuthor
Level 4
November 12, 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?

ParitMittal
ParitMittalAccepted solution
Level 10
November 17, 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                                                                                                                                                                                                                                                                                                                                                                                                                                    

AliMaleki
AliMalekiAuthor
Level 4
November 23, 2015

Thanks Parit. That's perfect!