Tracking conversation events as conversions with LinkedIn Insight Tags

Overview

We all know how important it is to track conversions and gain valuable insights about your site visitors. This tutorial shows you how to track Drift conversation events using LinkedIn Insight tags.

🚧

Warning:

This functionality will only work with chatbots and will not work with conversational landing pages (CLPs).

Before we get into the technical part of this tutorial, you’ll need to make sure you have the following prerequisites set up in LinkedIn:

For more information on Insight tags, please visit this FAQ page.

You’ll also want to make sure Drift has been installed on the pages where you're tracking events. If all the previous steps were followed correctly, and Drift has already been installed on the header of your site, your code should look similar to this snippet here:

<!-- Start of Async Drift Code -->
<script>
"use strict";

!function() {
  var t = window.driftt = window.drift = window.driftt || [];
  if (!t.init) {
    if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
    t.invoked = !0, t.methods = [ "identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on" ], 
    t.factory = function(e) {
      return function() {
        var n = Array.prototype.slice.call(arguments);
        return n.unshift(e), t.push(n), t;
      };
    }, t.methods.forEach(function(e) {
      t[e] = t.factory(e);
    }), t.load = function(t) {
      var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
      o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
      var i = document.getElementsByTagName("script")[0];
      i.parentNode.insertBefore(o, i);
    };
  }
}();
drift.SNIPPET_VERSION = '0.3.1';
drift.load('REPLACE WITH YOUR ACCOUNT EMEBED ID');
</script>
<!-- End of Async Drift Code -->

<body>
<!--Insight Tag from LinkedIn-->
   <script type="text/javascript">
       _linkedin_partner_id = "YOUR PARTNER ID GOES HERE";
       window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
       window._linkedin_data_partner_ids.push(_linkedin_partner_id);
   </script>
   <script type="text/javascript">
       (function (l) {
           if (!l) {
               window.lintrk = function (a, b) { window.lintrk.q.push([a, b]) };
               window.lintrk.q = []
           }
           var s = document.getElementsByTagName("script")[0];
           var b = document.createElement("script");
           b.type = "text/javascript"; b.async = true;
           b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
           s.parentNode.insertBefore(b, s);
       })(window.lintrk);
   </script>
   <noscript>
       <img height="1" width="1" style="display:none;" alt=""
           src="https://px.ads.linkedin.com/collect/?pid=xxxxxxxx&fmt=gif" />
   </noscript>
   <!-- End of insight tag code-->
</body>

Next, we'll need to set up our event listeners to begin tracking specific conversation events. In this tutorial we will be tracking the emailCapture event and create a function that will add the source pixel from your ad campaign.

For a full list of Drift events, please see this article.

function conversionTracker() {
  var img = document.createElement("img");
  img.setAttribute("src", "https://px.ads.linkedin.com/collect/?pid=xxxxxxx&conversionId=xxxxxxx&fmt=gif");
  document.body.appendChild(img);
}

This function creates an img attribute and sets the source attribute. For this function to push the conversion event to your ad campaign successfully, you’ll need to replace your pid and conversionId in the code with your own. This should be provided to you after creating your conversion for an event-specific pixel.

Example:
<img height="1" width="1" style="display:none;" alt="" src="***https://px.ads.linkedin.com/collect/?pid=xxxxxxxx&conversionId=xxxxxxx&fmt=gif***" />

📘

Note:

The src value copied from the img pixel in LinkedIn should replace the values in the code snippet above.

Lastly, let's set up our Drift event and execute our conversionTracker function when the emailCapture event has been triggered in the chat.

drift.on("emailCapture", function(data) {
  conversionTracker();
});

function conversionTracker() {
  var img = document.createElement("img");
  img.setAttribute("src", "https://px.ads.linkedin.com/collect/?pid=xxxxxxxx&conversionId=xxxxxxx&fmt=gif");
  document.body.appendChild(img);
}
<html>
<head>
    <title>LinkedIn Tracking</title>
    <script>
        "use strict";

        !(function () {
            var t = (window.driftt = window.drift = window.driftt || []);
            if (!t.init) {
                if (t.invoked)
                    return void (
                        window.console &&
                        console.error &&
                        console.error("Drift snippet included twice.")
                    );
                (t.invoked = !0),
                    (t.methods = [
                        "identify",
                        "config",
                        "track",
                        "reset",
                        "debug",
                        "show",
                        "ping",
                        "page",
                        "hide",
                        "off",
                        "on",
                    ]),
                    (t.factory = function (e) {
                        return function () {
                            var n = Array.prototype.slice.call(arguments);
                            return n.unshift(e), t.push(n), t;
                        };
                    }),
                    t.methods.forEach(function (e) {
                        t[e] = t.factory(e);
                    }),
                    (t.load = function (t) {
                        var e = 3e5,
                            n = Math.ceil(new Date() / e) * e,
                            o = document.createElement("script");
                        (o.type = "text/javascript"),
                            (o.async = !0),
                            (o.crossorigin = "anonymous"),
                            (o.src =
                                "https://js.driftt.com/include/" + n + "/" + t + ".js");
                        var i = document.getElementsByTagName("script")[0];
                        i.parentNode.insertBefore(o, i);
                    });
            }
        })();
        drift.SNIPPET_VERSION = "0.3.1";
        drift.load("YOUR ACCOUNT EMBED ID GOES HERE");


        drift.on("emailCapture", function (data) {
            conversionTracker();
        });

        function conversionTracker() {
            var img = document.createElement("img");
            img.setAttribute("src", "https://px.ads.linkedin.com/collect/?pid=xxxxxx&conversionId=xxxxxxx&fmt=gif");
            document.body.appendChild(img);
            console.log('clicked', img);
        }
    </script>
</head>

<body>
    <!--Insight Tag from LinkedIn-->
    <script type="text/javascript">
        _linkedin_partner_id = "YOUR LINKEDIN PARTNER ID GOES HERE";
        window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
        window._linkedin_data_partner_ids.push(_linkedin_partner_id);
    </script>
    <script type="text/javascript">
        (function (l) {
            if (!l) {
                window.lintrk = function (a, b) { window.lintrk.q.push([a, b]) };
                window.lintrk.q = []
            }
            var s = document.getElementsByTagName("script")[0];
            var b = document.createElement("script");
            b.type = "text/javascript"; b.async = true;
            b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
            s.parentNode.insertBefore(b, s);
        })(window.lintrk);
    </script>
    <noscript>
        <img height="1" width="1" style="display:none;" alt=""
            src="https://px.ads.linkedin.com/collect/?pid=xxxxxxx&fmt=gif" />
    </noscript>
    <!-- End of insight tag code-->
</body>
</html>

Did this page help you?