Convert a string in the dataLayer to a number when saving to an eVar

Avatar

Avatar

philipk92120636

Avatar

philipk92120636

philipk92120636

13-06-2019

Probably a super simple one this.

 

Basically, I'm saving the price difference between two products.

 

In the dataLayer it's a string but it would be handy to save this as a number so I can use it for metrics.

 

How can I convert the value and save it to an eVar? I've tried the below, but it does absolutely nothing!

 

var priceDifference = _satellite.getVar("priceDifference");

if(priceDifference) {

    s.eVar77 = parseFloat(priceDifference);

}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

philipk92120636

Avatar

philipk92120636

philipk92120636

14-05-2020

I stuck with saving the value to an eVar as I couldn't achieve what I was after with the numeric or currency events.

Answers (7)

Answers (7)

Avatar

Avatar

ursboller

MVP

Total Posts

1.0K

Likes

484

Correct Answer

250

Avatar

ursboller

MVP

Total Posts

1.0K

Likes

484

Correct Answer

250
ursboller
MVP

14-06-2019

please let me know, I'm interested if decimals show up by default or not.

remark: if you later have another currency, you could still use an additional numeric event (for the other currency) and track in already existing currency event the corresponding value.

simple example (USD Report Suite): if user buy for 10 EUR you report this in a new event ("10") while you write in the old event the corresponding USD amount. this way you can report in USD overall, USD amount from EUR (hit segment where both events are set) and EUR amount (new numeric event als calculated metric)

Avatar

Avatar

philipk92120636

Avatar

philipk92120636

philipk92120636

14-06-2019

Thank you for the comprehensive response. I've used currency as we're only dealing with one currency type. I'll see if the values have decimal places.

Avatar

Avatar

ursboller

MVP

Total Posts

1.0K

Likes

484

Correct Answer

250

Avatar

ursboller

MVP

Total Posts

1.0K

Likes

484

Correct Answer

250
ursboller
MVP

14-06-2019

if you use a currency event, it will automatically show the currency (of the report suite) in reporting.

on the other hand, you can always create a calculated metric and change to whatever you want to display (currency, numeric,...)

If you only collect and report in one currency (the report suite currency), I would take a currency event. in other cases it's worth to think about using a numeric event.

remark: be aware that by default Adobe Workspace will not display decimals (at least for numeric events). that means if you use a numeric event with decimal numbers, the default metric will just show the full numbers. you can create a calculated metric just containing the original metric and set decimals to whatever you want...

I don't know what default settings for currency metrics is, worth a try...

remark 2: if you only use the calculated metric for reporting think about changing the setting of the metric to be a "builder metric". this will prevent the metric to show up for reporting while it can still be used within segments or calculated metrics. this will reduce the number of times the end user takes the wrong metric

Avatar

Avatar

philipk92120636

Avatar

philipk92120636

philipk92120636

14-06-2019

I've set up an event that captures the value of the price difference. Is it better to use numeric or currency when setting up the event type? The values coming in will always be monetary amounts.

Avatar

Avatar

philipk92120636

Avatar

philipk92120636

philipk92120636

14-06-2019

Ah yes. Thanks for spotting that!

Avatar

Avatar

ursboller

MVP

Total Posts

1.0K

Likes

484

Correct Answer

250

Avatar

ursboller

MVP

Total Posts

1.0K

Likes

484

Correct Answer

250
ursboller
MVP

13-06-2019

the question is: calculate in "javascript" (on website) or within Adobe Analytics.

if "Adobe Analytics": having the number in an eVar cant be used for calculation. better use a numeric event like "event1=123"

Avatar

Avatar

Andrey_Osadchuk

MVP

Avatar

Andrey_Osadchuk

MVP

Andrey_Osadchuk
MVP

13-06-2019

It is not necessary to convert a number in the string format into a real number if you want to capture it in eVars.

Pay attention, that the eVar syntax above is inaccurate. The correct one is as follows:

s.eVar77