SFMC Cloud Pages – logging with custom error pages

Frustrated ampscript developer

Did you know, that since last year, it has been possible to create custom error pages for Cloud Pages in Salesforce Marketing Cloud? You can do this by creating a new Cloud Page like you would normally do, and select the appropriate Error Content under Advanced options:

Settings for creating a custom error page in Salesforce

This is a really nice addition, allowing you to show a more “user friendly” and branded error page for your visitors than the usual error 500:

But there is more to this. Let’s say you are trying your best to catch all the errors already with try/catch SSSJ, but there might be some gaps. How would you know which of your many cloud pages are actually throwing error 500? It might happen in very rare occasions, which you really have not expected. Well, you can create a quick data extension, with two fields: URL – Text(2000) and Timestamp – Date. The Timestamp field should have the default value of Current date:

This data extension will be receiving information on the URLs of Cloud Pages which cause error 500, and hence make your new custom error page appear. You only need to create this data extension and error page once, in your ENT BU (unless you want specific branded versions in child BUs). The only drawback is, that the personalisation string, memberid, will always be the one of where the error page is hosted, hence there will be no info on which Business Unit hosts the erroring Cloud Page.

The code to insert the URL into the data extension is quite simple:

set @insert = insertData("CP_errorLog","url", RequestParameter('PageURL'))

And yes, I have tested – even though the RequestParameter('PageURL') function is written in the error page, it is not the URL of error page that is retrieved, but the one of your original Cloud Page. You can also see, that when your new error page is shown, the URL in browser does not redirect to the error page – but remains as the original one. In case any query parameters are added to the url, these are included in the “dump” allowing you to debug specific cases.

I am yet to find a way of fetching and storing subscriber specific data (like jobid and subscriber key) allowing for even more detailed debugging and error reproduction.

A similar solution can be used to identify Cloud Pages which are resulting in error 404 (not found). This might be causes by external pages linking to e.g unpublished or deleted urls. You should use similar approach, but choose “Uses for not found errors 404” in the drop down under Advanced settings in Cloud Page creation flow.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top