Expand my Community achievements bar.

Join us at Adobe Summit 2024 for the Coffee Break Q&A Live series, a unique opportunity to network with and learn from expert users, the Adobe product team, and Adobe partners in a small group, 30 minute AMA conversations.
SOLVED

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

Avatar

Level 5

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

}

1 Accepted Solution

Avatar

Correct answer by
Level 5

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

View solution in original post

9 Replies

Avatar

Level 10

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

Avatar

Community Advisor

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

Level 5

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

Community Advisor

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

Level 5

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

Community Advisor

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

Level 10
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?

Avatar

Correct answer by
Level 5

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