Contact Us

March 14, 2025

June 24, 2026 6:06 pm

Collecting previous page url in cloudpage

Share with

Understanding the Problem

When a user visits a CloudPage, the previous page’s URL is not automatically passed to the CloudPage. To collect this information, teams need to implement a solution that can capture the previous page’s URL and pass it to the CloudPage.

The root cause of this challenge is the lack of a built-in mechanism in CloudPages to collect the previous page’s URL. This requires teams to implement custom solutions using JavaScript, AMPscript, or other programming languages.

Possible Solutions

There are a few possible solutions to collect the previous page’s URL in a CloudPage. One solution is to use JavaScript to dynamically add the previous page’s URL as a parameter to the link that points to the CloudPage. Another solution is to use AMPscript to pass the URL as a parameter between two CloudPages.

AMPscript example

%%=CloudPagesURL(ID_OF_PAGE_B, 'ref', RequestParameter('PAGEURL'))=%%

Alternatively, teams can use the Referer header to collect the previous page’s URL. However, this method is not reliable and may not work in all scenarios.

Best Practices

To ensure a reliable solution, teams should consider the following best practices:

Checklist

  • Control the previous website and add JavaScript to collect the URL
  • Use AMPscript to pass the URL as a parameter between two CloudPages
  • Avoid using the Referer header due to its unreliability
  • Test the solution thoroughly to ensure it works in all scenarios
  • Consider security checks and potential impact on the solution

By following these best practices and considering the possible solutions, teams can effectively collect the previous page’s URL in a CloudPage.

Heads up: The solution may vary depending on the specific use case and requirements.

What is the most reliable method to collect the previous page’s URL?

Using JavaScript to dynamically add the previous page’s URL as a parameter to the link that points to the CloudPage is the most reliable method.

Can I use the Referer header to collect the previous page’s URL?

While it’s possible to use the Referer header, it’s not a reliable method and may not work in all scenarios.

What is the role of AMPscript in collecting the previous page’s URL?

AMPscript can be used to pass the URL as a parameter between two CloudPages, providing a reliable solution for this specific use case.

How do I ensure the solution works in all scenarios?

Thorough testing is essential to ensure the solution works in all scenarios, including different browsers, devices, and network conditions.

Genetrix Technology · Salesforce Marketing Cloud Partner

Need help shipping this in production?

Genetrix builds and untangles Salesforce Marketing Cloud and Agentforce setups for teams that want it done right the first time. If anything in this post sounds familiar, talk to us before it ships.

Get in Touch with Genetrix →

Blogs for the

Business-Savvy!​

Let’s Connect

A 30 min no cost strategy session
with cloud support expert

Let’s Connect

A 30 min no cost strategy session
with cloud support expert