SSJS function runs more than once in Landing Page

cloudpagelanding-pagemarketing-cloudssjs

I have an email template with a clickable image in it. The URL for that image is a landing page with parameters attached. The scope of the landing page is to capture the parameters from the URL and save the data in a Data Extension using WSProxy.

Here is the full code of the landing page:

<script runat="server">
  Platform.Load("Core","1.1.1");
  
  var deLog = DataExtension.Init('06D8E8FD-1796-473C-9634-EA5F732816A2'); // Evaluare comanda Log
  var prox = new Script.Util.WSProxy();
  
  function Update(OrderId, SubscriberKey, Email, ClientId, Response) {
    var updateDE = {
      CustomerKey: '8A439AF3-0829-49FF-A9B2-9E0D063120D5',
      Properties: [
        {
          Name: 'OrderId',
          Value: OrderId
        },
        {
          Name: 'SubscriberKey',
          Value: SubscriberKey
        },
        {
          Name: 'EmailAddress',
          Value: Email
        },
        {
          Name: 'ClientId',
          Value: ClientId
        },
        {
          Name: 'Rating',
          Value: Response
        },
        {
          Name: 'DataRating',
          Value: DateTime.SystemDateToLocalDate(Date.now())
        }
      ]
    };

    var options = { 
      SaveOptions: [{
        PropertyName: "*",
        SaveAction: "UpdateAdd"
      }]
    };

    var UpdateResponse = prox.updateItem('DataExtensionObject', updateDE, options);
    deLog.Rows.Add({Message: 'Update Response: ' + Platform.Function.Stringify(UpdateResponse)});
  }
  
  try{
</script>

%%[ 
VAR @Response, @OrderId, @DataRating, @SubscriberKey, @Email

SET @Response = RequestParameter('Response')
SET @SubscriberKey = RequestParameter('SubscriberKey')
SET @Email = RequestParameter('Email')
SET @OrderId = RequestParameter('OrderId')
SET @ClientId = RequestParameter('ClientId')
]%%

<script runat="server">
    var OrderId = Variable.GetValue("@OrderId");
    var SubscriberKey = Variable.GetValue("@SubscriberKey");
    var Email = Variable.GetValue("@Email");
    var ClientId = Variable.GetValue("@ClientId");
    var Response = Variable.GetValue("@Response");
    
    if(Response) {
      Update(OrderId, SubscriberKey, Email, ClientId, Response);
    } else {
      deLog.Rows.Add({Message: 'No Response found'});
    }
</script>
 
<br>OrderId: %%=v(@OrderId)=%%
<br>Subscriber Key: %%=v(@SubscriberKey)=%%
<br>Email Address: %%=v(@Email)=%%
<br>Response: %%=v(@Response)=%%
<br>ClientId: %%=v(@ClientId)=%%

<script runat="server">
  } catch(e) {
    // Redirect works by throwing an exception, so if it is inside a try it will always end up in the catch statement
    // The below code is a workaround to ignore that exception and only save in the Log DE the error we did not expect
    var desc = e.description;
    
    if(desc.indexOf("ExactTarget.OMM.AMPScriptRedirectException") > -1) {
      Platform.Response.Write(desc);
    } else {
      deLog.Rows.Add({Message: Platform.Function.Stringify(e)});
      Write(Platform.Function.Stringify(e));
    }
    
  }
</script>

The code works and the data is upserted in the Data Extension but the script runs more than once. Sometime twice and sometime thrice. Couldn't find any rule or reason behind it. Anyone knows why it runs more than once?

Best Answer

After some more testing I figure it out.

This behavior was identified only on Outlook, on Yahoo and Gmail it works as expected. Because we don't have the SSL enabled yet, the URL is under http format and Outlook has a security check in place. We expect for this behavior to disappear after we enable the SSL and change the URL to https format.

Related Topic