How to Log a Custom Event Error and send an Email Notifier
Last updated
Last updated
In this document, we'll walk through the process of creating a Web Page that allows users to submit custom errors that are then logged as a Custom Event and flagged via an Email Notifier.
The concepts covered in this document are relevant to the practicalities of using the Log Custom Event Action as well as publishing an app so that errors that occur within it are not only logged but also submitted via Email Notifier. Similar concepts are covered in Configuring App Error Notifications to Slack, which discusses Slack Notifiers as opposed to Email Notifiers and Application Errors as opposed to Custom Event Errors.
This section assumes you have already created an app and are working on it within the Web Builder in the Airkit Studio. The UI described can stand on its own if connected to a link in Journey Builder, or it can be part of a larger application flow.
Create a new Web Page and call it "Submit Error Web Page":
Add Text Area Input Box Web Control to the "Submit Error Web Page". This is where users will submit their custom error messages. Note that, upon creation, the input is bound to the variable name text_area. Leave this as it is:
Add a Button Web Control and change the associated text to "Submit Error":
While still inspecting the "Submit Error" Button, open the Actions tab in the Inspector to open the Action Builder. Click on the '+' icon to the right of the Clicked branch and add a Custom Log Event Action.
Change the Event Message to "User submitted custom error", the Log Level to ERROR, and the Metadata to "User submitted the following message: {{text_area}}". Note the presence of quotation marks to designate strings, and the presence of double brackets to designate variables within those strings; this is required to be Airscript-parsable, and both Event Message and Metadata expect information in the form of Airscript:
Upon completing the steps in this section, it is possible to publish this app as-is. The submitted error will be logged with the other Airkit Events; it can be accessed in the Console, under the Activity section.
Save your changes, exit the Studio, and return to the Console. Access Settings > Logs and Notifiers.
Scroll down to the Notifiers section and click on the associated Create new button.
Clicking on this button will open the Inspector, which will contain the tools to define the details of the new notifier being created. Name this new notifier "error_email_notification":
Under Destination, select Email:
Once Email is selected under Destination, a new input box labeled Email will appear beneath it. Enter the email address that you want to send custom error notifications to. (You will need to check this email address to see related notifications, so make sure you enter an email address that you can easily access.)
Click on the Create button on the bottom right.
Once a notifier is set up, you can test it by inspecting it and clicking on the Send Test button at the bottom of the Inspector. If properly set up, a test email should appear in the inbox of the designated email account.
Upon completing the steps in this section, you have created an Email Notifier. All apps within your Organization will have access to this notifier. It can be used by any app to send errors of any kind. There are no limits to the number of errors types that can be associated with a single notifier.
Most components of of Airkit apps can be tested by previewing them, but this is not the case with notifiers, because notifiers are set up as part of the publishing process. In order to confirm that an Email Notifier is properly sent when a Custom Event Error is logged, the following publishing procedure must be done first:
Return to accessing your App in the Airkit Studio and publish your application by clicking on the Publish button on the upper right. This will open the following window:
Expand the Notifications section:
Under Custom Log Error Event, select error_email_notification.
Click the Publish button on the bottom left of the window.
Upon completing the steps in this section, the application will be published, and any error submitted through the Log Custom Event Action will not only be logged with other the other Airkit Events, it will also be sent to the designated email address.
Access the published application via the designated link. This will appear in the window that opens upon publication:
It can also be found by inspecting the app in the Console:
Enter some test information in the text box and press the "Submit Error" button:
Check the relevant email inbox and look for the error message. Note how the message appears so that you can see the Event Message ("User submitted custom error") associated with the Log Custom Event Action, as well as the Metadata ("User submitted the following message: {{text_area}}"), which contains the test information as text_area.