1

I have a record of Score in a DE which is recorded as number and I want to create a star rating display in the email based on the score number.

e.g if the score is 3.6 show 3 stars and a half or if a score is 3.9 show 4 stars or if a score is 4.1 show 4 stars

I'm thinking to create the images with the star rating, 1 star, 1 and a half, 2 stars, 2 and a half and so on, host them and get a link for each one and link it with the Score number and then create some if/else AMPscript to display it.

Would this work or can you think of a better way of doing this?

7

Short Answer is 'Yes'

Long answer is that I have seen 2 approaches to this:

  1. Upload 3 images - one with a full star, one with a half star and 1 with an empty star
  2. Upload 11 images - one for each half star increment from empty to 5 stars

With Option 1, you would just create a for loop that would loop through the whole numbers to fill in the full stars. You then use the remainder to determine half stars and then loop again to fill in the empty stars to make the total be 5 stars displayed.

With Option 2, you would associate each estimated ranking with an image then use some math on the score stored in your DE to round up/down and then use that associated URL to display the corresponding image.

Option 1 is more dynamic and offers flexibility, but is also more process heavy and takes more development to get into place.

Option 2 is very structured and is not very flexible. You would also need an extra DE or other storage place to link the URLs to the score number. That being said though, this is the easiest one to maintain and is the lower development option.

I personally like Option 1 better, but in general, option 2 is likely the better solution for most due to the stability and efficiency it provides.

  • 1
    You could use ContentImageByKey and let Key contain the score - in that way, you would not need to link score number to image URL – Lukas Lunow Oct 15 at 9:11
  • Added AMPScript to support your answer Gortonington - feel free to transpose my answer into yours to provide a complete answer. – Cameron Robert Oct 16 at 8:20
1

Gortonington's Answer is Correct - Just adding the AMPScript to facilitate that answer

%%[
SET @stars = 3.7
SET @increment = 0.5
SET @newstars = Subtract(@stars, Mod(@stars, @increment))
]%% 
Stars: %%=v(@newstars)=%%

Output:
Stars: 3.5

You could then follow this with an IF statement to show the correct image, using the 2nd option in Gortonington's answer.

AMPScript Description:

  • Use @increment to specify the rounding of stars. Using "1" will make it whole stars, using "0.25" will enable quarter-stars.
  • @stars is the number of stars to assess.
  • The MOD Function finds the remainder after division of one number by another. Wiki on Modulo here.
  • Subtract does exactly what it says on the box.

Assumption:
You need to round down to the nearest @increment for marketing/legal reasons; 3.9 stars can not be legally advertised as 4 stars, etc.

0

You can use rather AMPScript as you suggest or standard Dynamic Content blocks so you don't have to code anything. So that, having one image per each number of stars, you will display the right one based on the value of the number in the Data Extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.