Launch: set a data element from within a rule? | Community
Skip to main content
New Participant
November 28, 2018
Solved

Launch: set a data element from within a rule?

  • November 28, 2018
  • 13 replies
  • 15468 views

How can I set a data element (I have it created as a custom code data element) from a rule? Basically I want the rule to fire when a user clicks a certain tile (there's a row of tiles with links). The following javascript figures out which tile it is and then tries to set the data element, but it's not working. tileIndex is correct, but the data element (featuredTileNumber) isn't getting set.

var tileIndex = $('.feature-tile-container .feature-tile .feature-tile-container__read-more-action .analytics-featuretitle-event').index(this)+1;

_satellite.logger.info('tile index= ' + tileIndex);

_satellite.setVar("featuredTileNumber",tileIndex);

_satellite.getVar("featuredTileNumber");

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 Stewart_Schilling

Are you saying that you have three ACTIONs in sequence?

Custom Code >> AA Set Variables >> AA Send Beacon

If so, then yes - it is a timing issue.  Custom Code runs asynchronously so the dynamic data element is not ready in time.

My suggestion (mentioned above) is slightly different.

In the CONDITIONs of your rule, create a Custom Code condition that sets your dynamic data element.  This will be sequentially executed (since condition MUST be evaluated first in order to determine if the rule actions are to be executed).

Then in your ACTIONs sequence, remove the custom code action, but keep the AA actions as-is.

Save, build, test, and report be in with your results.

13 replies

Stewart_Schilling
New Participant
December 5, 2018

Great to hear it!  Glad I could help. -Stew

New Participant
December 5, 2018

Thank you so much! That was it and it's working now. Seriously, I appreciate the effort to help me out. Also learned that you can't use spaces in the Custom Link name field.

Stewart_Schilling
Stewart_SchillingAccepted solution
New Participant
December 5, 2018

Are you saying that you have three ACTIONs in sequence?

Custom Code >> AA Set Variables >> AA Send Beacon

If so, then yes - it is a timing issue.  Custom Code runs asynchronously so the dynamic data element is not ready in time.

My suggestion (mentioned above) is slightly different.

In the CONDITIONs of your rule, create a Custom Code condition that sets your dynamic data element.  This will be sequentially executed (since condition MUST be evaluated first in order to determine if the rule actions are to be executed).

Then in your ACTIONs sequence, remove the custom code action, but keep the AA actions as-is.

Save, build, test, and report be in with your results.

New Participant
April 24, 2023

This didn't work for me, when I added my code in the 'CONDITION', the rule didn't fire at all. My code checks if a button is clicked and sets the corresponding member in the xdm object. 

 

document.querySelector('#buy').addEventListener('click', function () {

    MyObject["clickAction"] = "set";

})

 

I don't see the rule being fired 

New Participant
December 5, 2018

That's just what I'm calling the dynamic data element I created in the previous script.

_satellite.setVar("featuredTileNumber2",tileIndex.toString());

Stewart_Schilling
New Participant
December 5, 2018

Where is the “2” coming from ath end of featuredTileNumber2.  ??

New Participant
December 4, 2018

Thanks for the help but it's still not displaying - I'm just getting %featuredTileNumber2% writing out when the tag fires.

I wonder if it's my order of events somehow? I have a custom code block (where I have this js) -> set Analytics -> Set Beacon. Here's my console output:

   [Adobe Analytics] Firing link track beacon using the values: {"linkType":"o","linkName":"%featuredTileNumber2%"}.

   [Custom Script] featured content link rule fired

   [Custom Script] tile index= 1

Stewart_Schilling
New Participant
December 4, 2018

Looks like you have an extra space in there.

If, after removing the space, it still doesn't work, try removing the prefixed text "FeaturedContentTile: " to see if the data element can be resolved. If so, you might consider adding the prefix before doing the setVar.

New Participant
December 4, 2018

Thanks! I just read about not being able to setVar on Data elements. One odd requirement I should have added to the post was that the marketing person wants to me add the index # into the custom link name field. Essentially like this:

We have a property in DTM that's doing this and they want to re-create it in Launch the same way, but that's where the value is failing. I tried creating the data element on the fly as you suggested but it's not passing (which looks like it worked in DTM).

Stewart_Schilling
New Participant
December 4, 2018

adria_a94067176
New Participant
December 4, 2018

by default smetrics doesn't exists in launch, it refers to window.s