Question

JQL for unique page visitors

  • 13 January 2022
  • 1 reply
  • 80 views

I’m trying to write JQL for a “Page Loaded” event to determine the number of unique visitors to our website (any page) but cannot quite get it right.

This returns an error “Cannot use 'in' operator to search for...”

function main() {

    return Events({

        from_date: "2021-12-01",

        to_date: "2021-12-31"

    }).filter(function (event) {

        return event.name == "Page Loaded" && "www.mysite.com" in event.properties["$current_url"]

    }).reduce(mixpanel.reducer.count());

}

This works, but returns the total count, not the unique count which reduce(mixpanel.reducer.count()) is suppose to do:
function main() {

    return Events({

        from_date: "2021-12-01",

        to_date: "2021-12-31",

        event_selectors: [{

                event: 'Page Loaded',

                selector: '"www.mysite.com" in properties["$current_url"]'

            }

        ]

    }).reduce(mixpanel.reducer.count());

}

 

Any ideas? Thanks.


1 reply

You need a .groupByUser(mixpanel.reducer.any()) as well as a .reduce(mixpanel.reducer.count())

So…

function main()
{
  return Events({
     from_date: '2022-05-11',
     to_date: '2022-06-10',
     event_selectors: [{
           event:'Page Loaded',
           selector:'"www.mysite.com" in properties["$current_url"]'
        }]
    })
  .groupByUser(mixpanel.reducer.any())
  .reduce(mixpanel.reducer.count());
}
 

Reply