Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

_satellite.setVar doesn't work

Avatar

Avatar
Validate 25
Level 4
cathyw49544988
Level 4

Likes

36 likes

Total Posts

155 posts

Correct Reply

2 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
cathyw49544988
Level 4

Likes

36 likes

Total Posts

155 posts

Correct Reply

2 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
cathyw49544988
Level 4

06-12-2017

I set the data element as JS  Object and leave it as a place holder. In my event rule, I tried to dynamically get the value and then use _satellite.setVar function to set the value of my data element. But it didn't work for me. Then I tested in console, 

_satellite.getVar('PageName')

"Home"

_satellite.setVar('PageName','test' )

undefined

_satellite.getVar('PageName')

"Home"

It seems that _satellite.setVar function didn't work for me. Anyone know why?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Contributor
MVP
joshd7227840
MVP

Likes

275 likes

Total Posts

241 posts

Correct Reply

70 solutions
Top badges earned
Contributor
Give Back 10
Give Back 5
Give Back 3
Give Back
View profile

Avatar
Contributor
MVP
joshd7227840
MVP

Likes

275 likes

Total Posts

241 posts

Correct Reply

70 solutions
Top badges earned
Contributor
Give Back 10
Give Back 5
Give Back 3
Give Back
View profile
joshd7227840
MVP

06-12-2017

The short answer:

Data Elements defined within the interface have a different namespace/scope than Data Elements defined on-the-fly with _satellite.setVar(), so they are evaluated/referenced from separate sources.

Longer answer:

When a Data Element is defined within the interfaced, it is stored within _satellite.dataElements

When a Data Element is defined on-the-fly using _satellite.setVar(), it is stored within _satellite.data.customVars

When you use _satellite.getVar() to get the value of a Data Element, DTM first looks in _satellite.dataElements for the Data Element. If it is found, it evaluates the Data Element based on its configuration (e.g. JS Object, CSS Selector, Custom Code). 

If the Data Element is not found, DTM then evaluates the Data Element name to see if it is a Built-In Data Element  (e.g. _satellite.getVar('hostname') will return location.hostname)

If the Data Element is still not found, DTM then looks for it in _satellite.data.customVars and returns the value if found, which is where Data Elements set from _satellite.setVar() are stored.

So the main two takeaways from all this are:

a)  You cannot set pre-defined Data Elements values using _satellite.setVar().  If you think about it, it doesn't really make sense to be able to do this, because it negates the purpose of configuring them in the interface to populate according to your configuration!

b) Take precaution in the Data Element names you choose to use when configuring them in the interface vs. on-the-fly with _satellite.setVar(), because you may get unexpected values returned if you use the same Data Element name in the interface as from _satellite.setVar().

Additional Note: I may be wrong, but I'm going to take a guess and assume maybe you created the Data Element within the interface as a placeholder so that it will appear in the dropdown fields within rules when using %data_element% syntax.   Unfortunately, Data Elements created using _satellite.setVar() will not appear in those dropdowns. However, you can still reference them in the fields using %data_element% syntax.  Internally DTM makes a _satellite.getVar() call just like you would in a custom js code box, so it will return the value from _satellite.data.customVars if not found elsewhere.

.josh

Answers (1)

Answers (1)

Avatar

Avatar
Validate 25
Level 4
cathyw49544988
Level 4

Likes

36 likes

Total Posts

155 posts

Correct Reply

2 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
cathyw49544988
Level 4

Likes

36 likes

Total Posts

155 posts

Correct Reply

2 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
cathyw49544988
Level 4

06-12-2017

Interesting. Thanks for your answer.