I am new to CloudPages, and have been trying to see if I can retrieve and record UTM parameters' values (in SFMC) - from URLs/visits from our FB ads.

I have found some examples of how to record CloudPages forms' values into an SFMC DE (https://medium.com/@saurabh.samirs/insert-data-into-data-extension-using-cloud-pages-and-ampscript-9d0f5ddd2342), or from SFMC email links/URLs (Update/Insert DE record on cloud page with parameters), but for URLs of visitors from other websites (FB ads in this case), I am not sure how to adjust it.

I have this code (before HTML, in a code snippet box) at the top of CloudPage:

var @campaign, @medium, @source, @p_utc
set @campaign = QueryParameter('utm_campaign')
set @medium = QueryParameter('utm_medium')
set @source = QueryParameter('utm_source')
set @p_utc = QueryParameter('p_utc')


But I'm afraid it gives a warning* when I try to publish the page, and if I publish it anyway, the link/page shows a 500 - Internal server error.

Have you come across an AMPScript which may work for this kind of (traffic from another website) URL parameters' tracking?

And perhaps I am not putting it in the right place.

An example of a URL from a FB ad would be: https://www.domain.com/promotions/book-online/info.php?p_language=en&utm_source=facebook&utm_medium=paid-social&utm_campaign=test_media&p_utc=CloudPageTest

P.S. we also have a PHP snippet before this AMPScript - to retreive the 'p_utc' parameter from the URL

// Start browser session
// Set the UTC if none set yet
if(empty($_SESSION['p_utc']) && !empty($_REQUEST['p_utc'])) {
 $_SESSION['p_utc'] = $_REQUEST['p_utc'];

*Error text (CloudPages):

An error occurred while previewing this content. This can happen for many reasons, including incomplete or incorrect MC scripting (AMPscript, SSJS or GTL) or missing subscriber context. Click Cancel to review your code or Publish to push the updated content live.

New contributor
Maria Ponomareva is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • You can't run PHP in a Cloud Page. The only server-side languages supported are AMPScript and Server-Side JavaScript (SSJS). If you ditch the PHP you'll probably find the page works - I can't see anything immediately wrong with your AMPScript Jun 24 at 3:49
  • that, and I would maybe add an "IF NOT EMPTY" bit around those vars that map to required fields in your DE. Your insert will break if a "required" value in the DE does not come in as parameter, and also output 500. Jun 24 at 9:36
  • Oh I see, thank you! I removed the PHP part, but I am afraid still getting an error. I am just worried it was needed to populate the href link with the p_utc parameters (= Campaign name) of the 2 buttons/CTAs on this page (i.e.: href="domain.com/promotions/book-online/…" ) - which should transfer this information to Tableau and GA (I hope). I will try to rewrite it in SSJS. I do not have required fields in the target DE (but will try to add the "IF NOT EMPTY" clause, thanks! Jun 24 at 18:25
  • P.S. and I put AMPScript in an HTML block (not a Code Snippet block), as I saw somewhere that this is how it is done.. And hid it with: <!--== and ==--> (it used to be visible). Jun 24 at 18:45
  • P.P.P.S. I realized, when I remove the 2nd part of AMPScript* - it works! (or at least I can publish the Cloud Page without an error). So the problem seems to be with the InsertData() part.. Ok. (will make sure IF EMPTY clause is there, although no required/non nullable fields in the target DE). * InsertData( "CloudPage_Parameters_test", "campaign",@campaign, "medium",@medium, "p_utc",@p_utc ) Jun 26 at 18:39


Your Answer

Maria Ponomareva is a new contributor. Be nice, and check out our Code of Conduct.

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

Browse other questions tagged or ask your own question.