0

I've created a piece of ampscript that needs to post form data to SalesCloud. Everything works fine, however I'm not able to pass the utm parameters from this url https://cloud.e.mywebsite.com/test-form-prod?utm_source=newsletter&utm_medium=email&utm_campaign=whitepaper&utm_content=form. I'm using the following script:

SET @UTM_Source = QueryParameter('utm_source') 
SET @UTM_Medium = QueryParameter('utm_medium') 
SET @UTM_Campaign = QueryParameter('utm_campaign') 
SET @UTM_Content = QueryParameter('utm_content') 

And then in the CreateSalesforceObject the following rules (example)

SET @leadId = CreateSalesforceObject(
  "Lead", 4,

    "UTMSource__c", @UTM_Source,
      "UTMMedium__c", @UTM_Medium,
      "UTMContent__c", @UTM_Content,
      "UTMCampaign__c", @UTM_Campaign)

For some reason it's not generating the parameters I have defined. Any ideas?

Thanks!

Edit: Complete code

%%[
/* form submission check */
IF RequestParameter("submitted") == true THEN

/* UTM Parameters */
SET @originId = "request-quote"
SET @UTM_Source = QueryParameter('utm_source') 
SET @UTM_Medium = QueryParameter('utm_medium') 
SET @UTM_Campaign = QueryParameter('utm_campaign') 
SET @UTM_Content = QueryParameter('utm_content') 
SET @UTM_Term = QueryParameter('utm_term') 

/* check if account already exists */
SET @accountRows = RetrieveSalesforceObjects(
  "Account",
  "Id,Name",
  "Name", "=", RequestParameter("company")
  )

/* get account id if contact already exists */
IF RowCount(@accountRows) > 0 THEN
SET @accountId = Field(Row(@accountRows, 1), "Id")
ENDIF

/* set consent checkbox */
IF RequestParameter("consent") == "on" THEN
SET @consent = "true"
ELSE SET @consent = "false"
ENDIF

/* check if contact already exists */
SET @contactRows = RetrieveSalesforceObjects(
  "Contact",
  "Id,Email",
  "Email", "=", RequestParameter("email")
  )

SET @leadRows = RetrieveSalesforceObjects(
  "Lead",
  "Id,Email",
  "Email", "=", RequestParameter("email")
  )

/* get contact id if contact already exists*/
IF RowCount(@contactRows) > 0 THEN
SET @contactId = Field(Row(@contactRows, 1), "Id")

/* update contact if already exists*/
SET @updateContactRecord = UpdateSingleSalesforceObject(
  "Contact", @contactId,
  "FirstName", RequestParameter("firstname"),
  "LastName", RequestParameter("lastname"),
  "AccountId", @accountId,
  "Phone", RequestParameter("phone"),
  "Country__c", RequestParameter("country"),
  "Industry__c", RequestParameter("industry"),
  "Role_in_the_buying_process__c", RequestParameter("role"),
  "CompanySize__c", RequestParameter("companysize"),
  "HasOptedInForEmail__c", @consent,
  "ContactOriginID__c", @originId,
  "Email", RequestParameter("email")
     )

/* update lead if already exists*/
ELSEIF RowCount(@leadRows) > 0 THEN
SET @leadId = Field(Row(@leadRows, 1), "Id")
SET @updateLeadRecord = UpdateSingleSalesforceObject(
  "Lead", @leadId,
  "FirstName", RequestParameter("firstname"),
  "LastName", RequestParameter("lastname"),
  "Company", RequestParameter("company"),
  "Email", RequestParameter("email"),
  "Phone", RequestParameter("phone"),
  "Country__c", RequestParameter("country"),
  "State__c", RequestParameter("state"),
  "LeadIndustry__c", RequestParameter("industry"),
  "RoleInTheBuyingProcess__c", RequestParameter("jobrole"),
  "CompanySize__c", RequestParameter("companysize"),
  "HasOptedInForEmail__c", @consent,
  "LeadOriginId__c", @originId
  )


/* create lead */
ELSE SET @leadId = CreateSalesforceObject(
  "Lead", 16,
  "FirstName", RequestParameter("firstname"),
  "LastName", RequestParameter("lastname"),
  "Company", RequestParameter("company"),
  "Email", RequestParameter("email"),
  "Phone", RequestParameter("phone"),
  "Country__c", RequestParameter("country"),
  "State__c", RequestParameter("state"),
  "LeadIndustry__c", RequestParameter("industry"),
  "RoleInTheBuyingProcess__c", RequestParameter("role"),
  "CompanySize__c", RequestParameter("companysize"),
  "HasOptedInForEmail__c", @consent,
  "LeadOriginId__c", @originId,
  "UTMSource__c", @UTM_Source,
  "UTMMedium__c", @UTM_Medium,
  "UTMContent__c", @UTM_Content,
  "UTMCampaign__c", @UTM_Campaign
  )

ENDIF


]%%

Form

<h2>Thank you for submitting the form.</h2>

%%[ ELSE ]%%

HTML form

%%[ ENDIF ]%%

I've also tried this, but no luck

"UTMSource__c", RequestParameter('utm_source'),
  "UTMMedium__c", RequestParameter('utm_source'),
  "UTMContent__c", RequestParameter('utm_source'),
  "UTMCampaign__c", RequestParameter('utm_source')
12
  • Have you tried request parameter? Commented Apr 14, 2021 at 11:01
  • @SwatiMishra, yes I did! I tried both, but I got the same result Commented Apr 14, 2021 at 11:09
  • Hi Daan - what is exactly happening, the lead doesn’t get created, or it does get created with blank fields? It seems that you are trying to create a lead with just 4 custom fields, and a standard Lead has some other mandatory fields. Maybe you could share more code for context?
    – zuzannamj
    Commented Apr 14, 2021 at 11:35
  • 2
    Ok two more questions: 1. How are you testing it? Are you actually redirecting from an email to the CloudPage? 2. Have you tried outputting the parameter values, eg. Output(QueryParameter('utm_source'))? That should tell you whether the problem is within the query function or later in the script
    – zuzannamj
    Commented Apr 14, 2021 at 16:09
  • 1
    I am running out of ideas... can you double check the UTM field API names in Salesforce? Check to see how those fields are set up in Salesforce? Maybe your MC Connect API user doesn’t have access to them?
    – zuzannamj
    Commented Apr 14, 2021 at 20:38

1 Answer 1

0

I spoke to the Salesforce Support and we came up with the following solution. After the submit the variables for the UTM parameters weren't being generated in time. To fix this the following hidden form:

<input name="utm_source" type="hidden" value="%%=v(@UTM_Source)=%%"><br>
<input name="utm_medium" type="hidden" value="%%=v(@UTM_Medium)=%%"><br>
<input name="utm_campaign" type="hidden" value="%%=v(@UTM_Campaign)=%%"><br>
<input name="utm_content" type="hidden" value="%%=v(@UTM_Content)=%%"><br>

This fixed the issue.

Thanks for all the help!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .