Include Ratings Links or NPS Surveys in an Email

Overview

Klaviyo does not currently support including form elements inside an email, but it is possible to include links in your email to collect information from users and then send that information back to Klaviyo as a custom property. A common use-case for this is including Rating Links in an email is an NPS Survey.

This feature requires a technical understanding of URL arguments, and knowing how to handle those arguments from your website either server-side or client-side (with JavaScript). The steps required to make this work include:

  • Adding links in your email template, with URL arguments for each rating, that direct to a page on your website that will handle these arguments
  • Implementing code on your website that pulls the right URL arguments to be used in a Klaviyo event
  • Send a track or identify event with the rating the user gave back to Klaviyo

Configure your Email Template to Collect User Ratings

From Klaviyo's end you will have to create a link/button inside a template for each rating that a user can select. In this example, we will create a 1-10 scoring system and will thus need ten buttons for each value 1-10.

Each button should link to the page on your website where you will handle this data and include two URL arguments:

http://yourwebsite.com/?score=1&user={{ email }}
  • http://yourwebsite.com/
    The URL to your external page that will handle the data from Klaviyo
  • ?score=1
    This would be for the first button, as the value here is 1; repeat this for each button with the correct value for that button
  • &user={{ email }}
    This argument should be kept the same for all buttons, and will dynamically populate with the recipient's email address
644663

Configure your Website to Capture and Sync Rating to Klaviyo

When someone clicks on a configured rating link in your email, he/she will be taken to your website and the selected rating will be preserved in the URL. The &user={{ email }} argument will also populate with the recipient's email address.

To work with this data and send it back to Klaviyo, you will have to handle these URL arguments passed through the link, and then send a track or identify call back to Klaviyo with that information. You can do this either server-side or client-side.

Here, we will share an example of how to set this up using JavaScript. In this example, we are creating a custom property called "NPS" that will populate with each user's selected ranking. To get this feature working, you simply have to prepare your email template as directed above and add the following snippet of code to the page on your website where recipients are getting directed:

<script type="text/javascript">
    function get(name){
        if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
        return decodeURIComponent(name[1]);
    }
</script>

<script type="text/javascript">
    var _learnq = _learnq || [];
    _learnq.push(['account', 'YOUR_ACCOUNT_ID']);
    _learnq.push(['identify', {
        '$email' : get("user"),
        'NPS': get("score")
    }]);
   (function () {
        var b = document.createElement('script'); b.type = 'text/javascript'; b.async = true;
        b.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'a.klaviyo.com/media/js/analytics/analytics.js';
        var a = document.getElementsByTagName('script')[0]; a.parentNode.insertBefore(b, a);
    })();
</script>

Where you see Your_Account_ID, replace with your account's Klaviyo Public API Key.

When someone receives your rating email and clicks a rating button, he/she will get taken to the page you've designated. The JavaScript will pull in the selected "score" and pull in the person's email address. Then, it will use Klaviyo's API to assign the "score" to the person's profile as a custom property labeled "NPS."

Was this article helpful?
0 out of 0 found this helpful