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

Profile Script return numerical value

Avatar

Avatar
Validate 10
Level 2
chrisw78940856
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
chrisw78940856
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile
chrisw78940856
Level 2

28-07-2017

Hi,

I've created a profile script which is taking an mbox parameter for 'Sign up date' (which is a text string: "yyyy-mm-dd"), and converting it into a number, whose digits are YYYYMMDD. The value returned in mboxTrace for my test account is ''2.0170713E7" (13th July 2017).

My hope is to then create an audience with criteria like "user.param IS GREATER THAN 20170728", or any others as and when they are needed. I.e., this is saying 'only target visitors who signed up after 28th July 2017'.

After testing, it doesn't appear to be working as expected. In some cases my content shows correctly, and others it doesn't, but it doesn't seem to correlate with numerical magnitude.

Is the 'greater than' criteria a sensible thing to use for user parameters, or are they always returned as text strings? If so, does anyone have an idea for an alternative solution?

Many thanks,

Chris

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 5
Level 3
LJ_Jones
Level 3

Likes

27 likes

Total Posts

37 posts

Correct Reply

8 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile

Avatar
Boost 5
Level 3
LJ_Jones
Level 3

Likes

27 likes

Total Posts

37 posts

Correct Reply

8 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile
LJ_Jones
Level 3

29-07-2017

Your code looks fine.  So I would take a look at the data that is passed in your mbox.param('registrationdate') and validate that its always returning a date that you can use.  Since its a string, if there are any letters or other characters in there, it could be causing an error.  If the first character cannot be converted to a number, parseInt() returns NaN.

First you could try and run a regex to remove all non digits from the string before converting it to a number.  Something like:

var dateText = year + month + day;

dateText = dateText.replace(/\D/g,'');

var date = parseInt(dateText);

Second idea, would be to do the date comparison within the profile script and return true if its greater than.  Basically convert the string to a date and then do the comparison in JS.  The limitation here would be that you would have a hard coded date and not a dynamic date that you could change for different campaigns within your test setup.

Answers (3)

Answers (3)

Avatar

Avatar
Validate 10
Level 2
chrisw78940856
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
chrisw78940856
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile
chrisw78940856
Level 2

04-08-2017

Thanks very much, it appears to work fine now.

Chris

Avatar

Avatar
Validate 10
Level 2
chrisw78940856
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
chrisw78940856
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile
chrisw78940856
Level 2

28-07-2017

Sure, script below:

if (mbox.name == 'dashboard_header_banner') {

      var signUpDate = mbox.param('registration_date'); //"yyyy-mm-dd"

      var day = signUpDate.split("-")[2];

      var month = signUpDate.split("-")[1];

      var year = signUpDate.split("-")[0];

      var dateText = year + month + day;

      var date = parseInt(dateText);

      return date

}

The 'E7' just means x10^7. It's shorthand; the date format I've used yields a number over 20 million, and it doesn't like having that many digits. It's still technically a number.

I did think it might be returning a string, though. Thought that it was possible to use numbers though, as the 'greater than' option is available to use.

Avatar

Avatar
Boost 5
Level 3
LJ_Jones
Level 3

Likes

27 likes

Total Posts

37 posts

Correct Reply

8 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile

Avatar
Boost 5
Level 3
LJ_Jones
Level 3

Likes

27 likes

Total Posts

37 posts

Correct Reply

8 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile
LJ_Jones
Level 3

28-07-2017

Can you post your full profile script code? Or if its long, at least the portion that the creates the date and converts the string to a number?  And also, in your value "2.0170713E7" there is a period and "E7".  Are these typos?  What is the E7?  I would think this is a string and not a number and therefore the greater than behaves differently with strings.