Product name upsert to a data extension on click and redirection to cloud thank you landing page through AMPscript

ampscriptmarketing-cloudupsert

as the title says, I have a number of products in an email in SFMC. On click on any of the products, I'm trying to capture the product clicked on, upsert the name of it to a Data Extension then open / be redirected to a cloud thank you landing page saying something like "Hi FIRSTNAME, thanks for choosing PRODUCTNAME". I want to do this with AMPscript. Can anyone help please? Thanks!

Best Answer

This is fairly simple to do. There are 2 options on how to do this.

  1. Create a processing page to collect the product and upsert into the DE then redirect to landing page
  2. Create a landing page that first collects the product and upserts it to the DE then builds/displays the thank you page through variables and conditions.

My recommendation would be approach 2. This reduces the need for multiple pages, simplifying editing and maintenance - as well as reducing the number of redirects (which can sometimes cause issues if too many)

So for email link you would do something like:

<a href="%%=RedirectTo(CloudPagesURL(1234,"p","apple"))=%%">

Where the CloudpagesUrl function would set parameter p as the value of 'apple' (or whatever product name you want to pass).

Then on the page, you would put:

%%[
  set @product = RequestParameter("p")
]%%

Which would then collect the value of the parameter p that we set in the url in the email.

Then we would upsert it using the UpsertData Function.

From there you just use IF statements and other variables, etc. to create your page.

Like:

%%[ IF @product == "apple" THEN ]%%
An apple a day keeps the doctor away
%%[ ELSEIF @product == "orange" THEN ]%%
Orange you glad I didn't say apple?
%%[ ELSE ]%%
WATCH OUT FOR DOCTORS!
%%[ ENDIF ]%%