0

I am writing a JQL query to analyze MixPanel events. How can I group events by host name?

I tried this:

function(event) {return new URL(event.properties['$current_url']).hostname}

But I get an error that says "Precondition Failed."

I know this line of code is the problem, because the query works when I use a simpler statement (e.g. group by $current_url instead of host name).

srk
  • 1,625
  • 1
  • 10
  • 26

1 Answers1

0

I guess the URL reference was the problem. I was able to get it working with the help of this answer.

Define a function to parse the URL:

// Credit: https://stackoverflow.com/a/21553982/11838196
function getLocation(href) {
    var match = href.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
    return match && {
        href: href,
        protocol: match[1],
        host: match[2],
        hostname: match[3],
        port: match[4],
        pathname: match[5],
        search: match[6],
        hash: match[7]
    }
}

then use that function in JQL:

function(event) {return getLocation(event.properties['$current_url']).hostname}
srk
  • 1,625
  • 1
  • 10
  • 26