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

How to get eVar in a custom code JavaScript | Launch

Avatar

Avatar
Level 1
C_Evans
Level 1

Likes

0 likes

Total Posts

4 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
C_Evans
Level 1

Likes

0 likes

Total Posts

4 posts

Correct Reply

0 solutions
View profile
C_Evans
Level 1

13-05-2021

Hey guys,

I’m trying to get an eVar in a custom code box using JavaScript so I can pass it to another system. Documentation says it should be s.eVar. But of course that is returning "undefined" for me. My question is how can I get that variable?

 

The  Rule

C_Evans_0-1620967855771.png

The Code

C_Evans_1-1620967909515.png

The Console

C_Evans_2-1620968025718.png

 

 

Accepted Solutions (0)

Answers (3)

Answers (3)

Avatar

Avatar
Contributor
Level 3
jkm-disco
Level 3

Likes

22 likes

Total Posts

124 posts

Correct Reply

14 solutions
Top badges earned
Contributor
Shape 1
Give Back
Affirm 10
Applaud 25
View profile

Avatar
Contributor
Level 3
jkm-disco
Level 3

Likes

22 likes

Total Posts

124 posts

Correct Reply

14 solutions
Top badges earned
Contributor
Shape 1
Give Back
Affirm 10
Applaud 25
View profile
jkm-disco
Level 3

14-05-2021

Hi @C_Evans ,

 

Three Options (all require the Analytics extension to include the AppMeasurement code):

Option 1: Use custom code within an Analytics set variable action. This will always allow access to an object with the s namespace. The caveat there is, if the s object isn't set globally, you may have to send the beacons within the same rule as the custom code since you are referencing a local s object, but you could test to see if these values persist through other rules.

 

Option 2: As an alternative to option 1, you can make a local reference to an s object, or an object of any name with the behavior of the s namespace by calling the s_gi() function within your custom code, and this doesn't require being set within the Analytics action, ref. The caveat is that you would need to run the t() or tl() function to send the beacon from that new object.

 

Option 3: Change the settings in the Analytics extension to set the s object to be accessible globally. At that point, your custom code, and any other code on the page can reference the global s object.

 

Side note:

The _satellite object cannot access the variables as a direct property as a default behavior. If you had a data element that stored the value, you could run a _satellite.getVar(<variable name>) to view the value at execution time.

Avatar

Avatar
Boost 3
Level 1
tim_funk
Level 1

Likes

3 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Boost 3
Contributor
Applaud 5
Shape 1
Boost 1
View profile

Avatar
Boost 3
Level 1
tim_funk
Level 1

Likes

3 likes

Total Posts

18 posts

Correct Reply

0 solutions
Top badges earned
Boost 3
Contributor
Applaud 5
Shape 1
Boost 1
View profile
tim_funk
Level 1

18-05-2021

There are a 2 issues. (one right now, one I bet you'll discover later)

 

1) eVar38 is on the "s" variable. When editing custom code - The variable with the analytics attributes is "s". [But if you look in the browser during debugging, the minifier may change the variable to probably by "t".]

 

This means you want s.eVar38 ... or console.log("s.eVar38=" + s.eVar38)

 

2) The second error is setting s.eVar38 will do nothing unless Analytics knows to track it. You'll need to notify the analytics library to pull in that variable into the beacon via linkTrackVars. For example - this is probably what you will need:

 

s.eVar38 = magicBusinessLogicToPossiblePopulate()

if (s.eVar38) {

  if (s.linkTrackVars!=undefined && s.linkTrackVars.length>0) {

    s.linkTrackVars += ",eVar38"

  } else {

    s.linkTrackVars = "eVar38"

  }

}

 

All that being said - I agree with the other reply stating the value of eVar38 should instead be set in a data element. Then the analytics rule can be MUCH smpler by just pulling in that data element (with no extra code on the analytics rule)

 

 

Avatar

Avatar
Publish 1
MVP
yuhuisg
MVP

Likes

180 likes

Total Posts

541 posts

Correct Reply

106 solutions
Top badges earned
Publish 1
Affirm 100
Springboard
Bedrock
Validate 1
View profile

Avatar
Publish 1
MVP
yuhuisg
MVP

Likes

180 likes

Total Posts

541 posts

Correct Reply

106 solutions
Top badges earned
Publish 1
Affirm 100
Springboard
Bedrock
Validate 1
View profile
yuhuisg
MVP

15-05-2021

Instead of reading from your eVar38, how about reading from the data element that is being used to set eVar38?

For example:

You have a data element called "my variable".

And in your AA extension itself or in its "Set Variables" action, you have:

s.eVar38 = %my variable% // or s.eVar38 = _satellite.getVar("my variable");

In that case, you can use

console.log(_satellite.getVar("my variable"))

and it will return the same value as what has been set in eVar38.