I'm trying to create a cloudpage and call it into SMS through ampscript - when the user clicks the SMS link through SMS, the contact's phone number will be added to the data extension (and some other predefined fields), such as link URL and date stamp. I created it, but I failed. Is there any good example for me to refer to?

And the code in my CloudPage should look something like this:

 %%[var @phone
    set @phone = RequestParameter('phone')
    UpsertData('test_SMS',1,'phone',@phone,'Date clicked',Now())
    <a href="https://support.google.com/">click it</a>

And the code in my SMS content should look something like this:

<a title="Some page" 
alias="Some page">
Click to go there
  • 2
    Hello, it would be much easier to help you if you would attach your code to the question.
    – Niko
    Aug 11 at 8:28
  • Hello Niko,I have uploaded my code, please help me check the problem, thank you
    – yuyuuuu
    Aug 11 at 8:53

Points to check:

  1. First thing, you need to set the value for the @phone variable in your SMS since in your code you are just sending an empty value. You can use the MOBILE_NUMBER data string to dynamically populate the phone number of the SMS recipient within the send context. Check other strings here.
  2. SMS cannot handle HTML, since it is not a web-based platform, so you would need to remove all HTML tags in the SMS text.

Thus you would have something like that in the SMS text -

VAR @phone, @User_ID
SET @User_ID = AttributeValue("User_ID")
SET @phone = AttributeValue("MOBILE_NUMBER")
%%=RedirectTo(CloudPagesURL(2332, 'phone', @phone, 'userid', @User_ID))=%%

Then it should work correctly, as long as your CloudPage's UpsertData function is configured correctly, including Data Extension's name, fields' name and you are not missing any non-nullable fields.

Lastly, since SMS cannot understand HTML, your links would be displayed fully and this might look ugly, that is why it is recommended to shorten your links:

  • When you are creating the SMS in Journey Builder (or Content Builder) or directly in Mobile Connect, you can shorten only already created static links. Check out this article and this.
  • Or do an external API call to Bit.ly and dynamically shorten your link with dynamic values inside - that is what you have because of the phone number. Example here.
  • Hi Niko, thank you for your reply. Does the code in my cloudpage need to be modified? Is it right now? "Test_ SMS" is the Data Extension to be written, and "phone" is the number of the sending crowd.
    – yuyuuuu
    Aug 11 at 9:40
  • CloudPage's code is fine. Not sure what you meant by "number of the sending crowd" but "phone" has got to be the field in the "Test_ SMS" Data Extension.
    – Niko
    Aug 11 at 9:43
  • I want to write the user ID and number that clicked the link in SMS into the new de. the phone in SMS contnet is the phone in the sent SMS user de. what is your suggestion of "MOBILE_NUMBER" the field where the user number is stored? Or do you have any better suggestions?
    – yuyuuuu
    Aug 11 at 9:47
  • I have updated my answer to include "User_ID". Then, you would request this parameter on the CloudPage the same way as the "phone" one. As for the MOBILE_NUMBER, it system field that, so you can either use this one or reference the field that contains the phone number from the Sendable DE that you use to send an SMS.
    – Niko
    Aug 11 at 10:50
  • Hi Niko, thank you for your reply. How can I shorten my web link through the content in the SMS I have designed first ? Or can I directly use the cloudpage URL to use show shorten it and put it into the SMS content? In this case, how do I change my ampscript?
    – yuyuuuu
    Aug 11 at 16:41

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.