2 Useful Ways to Implement Logging in your SFMC Org

In the world of digital marketing, effective logging is crucial for maintaining the health of your campaigns and understanding customer interactions. In this post, we will look at two practical methods for implementing logging in Salesforce Marketing Cloud (SFMC):

  1. Logging errors in email sends
  2. Logging user events and errors on CloudPages (and websites that interact with SFMC)

These types of logs can help identify and diagnose issues quickly, detect unusual patterns (or unauthorized access attempts), and lead to the overall improvement of your SFMC org and marketing strategies.

1. Log and Debug Errors in Email Sends

Possible Scenarios:

  • Invalid Personalization Data: Data points used for personalization are missing or incorrect, such as a missing first name or an invalid promo code.
  • Data Privacy Restrictions: Issues arising from data privacy laws where certain data cannot be used or shared, causing errors in the email send process.
  • API Call Failures: Errors occurring when external API calls fail, such as retrieving dynamic content or fetching real-time data from an external system.

Let’s imagine you’re running a seasonal campaign and have inherited a simple journey aimed at re-engaging customers by reminding them of an unused promo code. An email in your journey might initially look like this:
(ampscript)

%%[
    VAR @emailAddress, @promoCodeRow, @promoCode
    SET @emailAddress = email
    SET @promoCodeRow = ClaimRow('PromoCodes', 'isClaimed', 'EmailAddress', @emailAddress)
    SET @promoCode = Field(@promoCodeRow, 'Code')
]%%

To enhance this with error handling and logging, we can introduce some simple improvements:

%%[
    VAR @emailAddress, @promoCodeRow, @promoCode
    SET @emailAddress = email
    SET @promoCodeRow = ClaimRow('PromoCodes', 'isClaimed', 'EmailAddress', @emailAddress)
    IF NOT EMPTY(@promoCodeRow) THEN
        SET @promoCode = Field(@promoCodeRow, 'Code')
    ELSE
        InsertDE('JourneyLog', 'Journey', 'Winback', 'Date', Now(), 'Email', @emailAddress, 'Message', 'No Promo Codes Available')
        RaiseError('No Promo Codes Available', false)
    ENDIF
]%%

In this improved version, if no promo codes are available, we log the error in a data extension and raise an error to ensure the email send fails gracefully. This pattern is applicable to all emails containing personalization, dynamic data, API calls, and more.

You never know when a campaign’s timeline or scope will change, so it’s important to have this type of additional security in place to ensure no errors make their way into emails sent to customers.

Steps to Implement

  1. Identify Required Data Points: Determine which data points are crucial for your email sends and could potentially cause failures.
  2. Wrap Logic in IF Statements: Use conditional statements to check for the presence and validity of these data points.
  3. Handle Errors Gracefully: Log relevant details to a data extension and raise appropriate errors to manage the email send process smoothly.

By following these steps, you can proactively manage errors, ensuring smooth operations and better insights into email performance.

2. Log User Events and Errors on CloudPages

Possible Scenarios:

  • Logging User Interactions with Preference Centers: Track when users update their preferences or subscribe/unsubscribe from certain communications.
  • Tracking Engagement with Personalized Offers: Monitor how users interact with personalized content, such as clicking on a personalized offer or completing a purchase.
  • Capturing Form Submission Errors: Log errors that occur during form submissions, such as missing required fields or invalid input.

Imagine you’re using a CloudPage to deliver personalized content or collect user preferences. With a few lines of code, you can efficiently log user interactions and errors.

To achieve this, we first need to create a Code Resource in Salesforce Marketing Cloud (SFMC). This Code Resource will act as our API endpoint. Our CloudPage will send events to this endpoint, which will then be recorded in our log.

Here’s a simple example of how you can set up a Code Resource to log events:

Now, from our CloudPage front end (or external website) we can send any events we’d like to log to our Code Resource endpoint as the user interacts with our page. And because CloudPages gives us subscriber data out of the box when a contact lands on it from one of our emails, we have all the information we need, giving us the ability to gain much more valuable metrics around how customers interact with our email campaigns.

Here’s a basic example:

(JS logging function on front-end CloudPage or external website)

Benefits:

  • Richer Metrics: Gain deeper insights into customer interactions with your email campaigns
  • Cross-Platform Logging: Log events from your website or mobile apps, providing a unified view of user behavior
  • Enhanced Personalization: Collect behavioral data to drive more personalized and real-time marketing efforts

By implementing these logging techniques, you can ensure better error handling and gain valuable insights into customer behavior. This approach allows you to start experimenting with data collection and usage before making a significant investment in a platform like Marketing Cloud Personalization or other Customer Data Platforms (CDPs). By understanding your current constraints and data requirements, you will be better prepared to leverage advanced personalization tools when the time is right.

Conclusion

Logging in SFMC can be a valuable tool to help you identify issues and understand user interactions. By implementing these logging techniques, you can ensure better error handling and gain valuable insights into customer behavior. Start experimenting with these methods today to optimize your marketing efforts and drive better results.


Want some help setting up proper logging in your SFMC org? (Or just want to talk about Salesforce?) Get in touch! 

You may be interested in

SFMC-Security-BestPractices

Best Practices to Keep Salesforce Marketing Cloud Secure

This post was written for Salesforce Marketing Cloud Admins and developers who want to learn how to leverage Salesforce Marketing Cloud (SFMC) while keeping their instance safe. In this blog, we cover three common mistakes SFMC professionals make when it comes to security. Continue reading to understand how to avoid these pitfalls and keep your […]

Read More

Vue.js and Salesforce Marketing Cloud: A Winning Combination for CloudPage Development

You’ve likely been hearing a lot lately about the importance of building a zero-party data strategy. At CloudKettle, we’re constantly thinking of ways that we can help our clients build engaging customer experiences that allow them to collect valuable zero-party data using Salesforce Marketing Cloud. My absolute favourite way to collect zero-party data is by […]

Read More

Sign up for the latest tips & news from CloudKettle

Thank you for subscribing.