How to track UTM parameters as Events in Drift

Updated 2 months ago ​by Ali Ukani

If you're using UTM parameters for links to your site, you can segment users based on which UTM campaign they arrived through by tracking an event in Drift.

Don't know what UTM parameters are? KissMetrics has a great writeup:

For example, suppose we have a Twitter ad campaign with this URL:

When a user lands on the page, we can check if the URL contains utm_source=twitter and utm_campaign=abm-meetup, and then track a "Clicked Twitter Ad" event for that user in Drift. Once the events are being tracked in Drift, we can create a dynamic segment for users who have tracked that event at least once.

Here's the complete code example:

window.drift.on("ready", function() {
  var queryString = window && window.location &&
  if (queryString) {
    if (/utm_source=twitter/.test(queryString) && /utm_campaign=abm-meetup/.test(queryString)) {
      window.drift.track("Clicked Twitter Ad ABM Meetup")

You can even copy and paste the above example onto your site. You'll want to change the name of the event passed to drift.track and also probably check for different UTM parameters. Make sure the code gets executed after the Drift JavaScript Snippet by placing its script tag after your snippet's script tag.

Was this article helpful?

Can’t find what you’re looking for?

Talk To Us