Convert a string in the dataLayer to a number when saving to an eVar | Community
Skip to main content
Level 4
June 13, 2019
Solved

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

  • June 13, 2019
  • 9 replies
  • 4534 views

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);

}

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 philipk92120636

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

9 replies

Andrey_Osadchuk
Level 10
June 13, 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

Urs_Boller
Community Advisor
Community Advisor
June 13, 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"

Level 4
June 14, 2019

Ah yes. Thanks for spotting that!

Level 4
June 14, 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.

Urs_Boller
Community Advisor
Community Advisor
June 14, 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

Level 4
June 14, 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.

Urs_Boller
Community Advisor
Community Advisor
June 14, 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)

jantzen_b
Adobe Employee
Adobe Employee
April 2, 2020
Do any of the answers below answer your initial question? If so, can you select one of them as the correct answer? If none of the answers already provided answer your question, can you provide additional information to better help the community solve your question?
philipk92120636AuthorAccepted solution
Level 4
May 14, 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.