Number stored as text? - How to convert from a prop/eVar to a metric | Community
Skip to main content
Andrew_Wathen_
Community Advisor
Community Advisor
July 14, 2022

Number stored as text? - How to convert from a prop/eVar to a metric

  • July 14, 2022
  • 5 replies
  • 2278 views

We all regret decisions in life; in Adobe Analytics we may regret storing a number in an eVar or prop! This is because unlike custom events, you can't perform numerical calculations (such as summing or averaging) on props or eVars.
Obviously, you can make changes to your implementation to capture these values in a custom event going forward. However, what can be done about your historical data? Fortunately, using a combination of Classifications and Calculated Metrics this can be taken care of.

Method

To explain the approach, I'm going to use the example of converting from a three-digit number stored in a prop, to a metric. However, this method can be extended to cope with any number of digits and decimal places as well.

Step1: Create classifications

We are going to use classifications to split our number up into separate classifications, one classification for each individual digit in the number.
In this example we are dealing with a three-digit number so we will need three classifications: one for the units, one for the tens, and one for the hundreds.

Step 2: Populate the classifications

We need to use the Classification Rule Builder to dynamically split the digits of the number into the three classifications.

For example, if the value in the prop was "874" then we would want the:

  • "units" classification to be dynamically set to "4"
  • "tens" classification to be dynamically set to "7"
  • "hundreds" classification to be dynamically set to "8"

To do this we require some RegEx:

  • (^\d*)(\d$) returns the ‘units’ in match group $2
  • (^\d*)(\d)(\d$) returns the ‘tens’ in match group $2
  •  (^\d*)(\d)(\d)(\d$) returns the ‘hundreds’ in match group $2 

Step 3: Build the calculated metric

The final step is to build a calculated metric to convert these classifications to numbers using the "if" function and static numbers.  For example...

  • If "unit" equals "1" then static number 1, plus
  • If "unit" equals "2" then static number 2, plus
  • If "unit" equals "3" then static number 3, plus
  • ...etc. (all the way to 9), plus
  • If "tens" equals "1" then static number 10, plus
  • If "tens" equals "2" then static number 20, plus
  • If "tens" equals "3" then static number 30, plus
  • ...etc. (all the way to 90), plus
  • If "hundreds" equals "1" then static number 100, plus
  • If "hundreds" equals "2" then static number 200, plus
  • If "hundreds" equals "3" then static number 300, plus
  • ...etc. (all the way to 900)

Screen shot of how this looks in the Calculated Metric Builder:

...and that's it! We now have a calculated metric for the values in the prop that we can perform numerical calculations on.

In conclusion, this method does take a bit of set up, but if you're stuck with a a number in a prop or eVar this may just save the day!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

Alexis_Cazes_
Level 10
July 18, 2022

This is a good description of a workaround. 

 

However I do miss the numeric 2 classification.

VaniBhemarasetty
Adobe Employee
Adobe Employee
July 22, 2022

@andrew_wathen_ Amazing workaround

Level 4
August 12, 2022

great work around! thanks for sharing

FrederikWerner
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
August 16, 2022

Glad we don't have to do this anymore in Customer Journey Analytics!

Learn more about Adobe Analytics and Customer Journey Analytics on my blogNeed help with Adobe Analytics or Customer Journey Analytics? Let's talk!
July 18, 2024

Hello,

My team used it to create a metric capturing the cart amount. I would like to see how you use your evar as a metric please?