Funnel analytic

Hello guys. I need to implement advanced funnel analytic, as descibed here: Funnel analysis - Wikipedia.
Please tell, does mongoDb is appropriate for this? And maybe any solution exists?
I can’t find anything in google about this topic.

Hi @111891 and welcome back :wink: !

This picture from your Wikipédia article:

Reminds me of the MongoDB Aggregation Pipeline:

Which you can basically sum up like this:

image

Each stage will apply a transformation to the documents in the pipeline in order to produce the final desired output. You can checkout the list of the 31 (more to code) aggregation pipeline stages in the doc.

The most common ones are:

  • $match: filtering
  • $group: grouping documents & accumulators (sum, avg, first, …)
  • $sort: sorting the docs
  • $skip: skipping some docs, usually for pagination
  • $limit: limit the nb of docs, usually for pagination
  • $project: reshaping / transforming the docs (calculation, etc)
  • $addFields: add (calculated) fields
  • $lookup: join docs with other docs (from another collection of the same collection)
  • $unwind: breaks down an array

So to sum up, yes, I think MongoDB is a good tool for this job. But you will need to learn the MongoDB Aggregation pipeline because it’s a very powerful querying language.

Good news: there is a free training for that available on the MongoDB University website: M121.

As a bonus, if you host your data in MongoDB Atlas, you also get access to Atlas Charts which will help you build dashboards which can be customized with… the aggregation pipeline :smiley: !

Here is an example dashboard I build for the Open Data COVID-19 project.

I hope this helps.

Cheers,
Maxime.

1 Like

Hi Maxime, Thank you for your reply. I know aggregation framework very well. But what you can say about such functionality
Parametric Aggregate Functions | ClickHouse Docs ?
Funnels, retentions, flows analytic. Mongodb not provide this type of functionality and haven’t any examples hot to do. It can’t be fetched using $group in example above, so your example woul’d not work. I read a lot of about mongodb aggregations and possibility but can’t find cases where peoples do such analytic using mongodb.

Your example wouldn’t work because the events must be in correct order.

Please read about Parametric Aggregate Functions | ClickHouse Docs and say does mongodb solve this cases and does mongodb is the right choice for that?

Maybe I’m misunderstanding but the first one at least in your link (Histogram) reminds me of the $bucket and $bucketAuto stages that we have in the aggregation pipeline.

I’m not sure which part you are referring to. But the aggregation pipeline is a Turing Complete language.

I even implemented the Game of Life with it. So really, you can do anything with it and manipulate the docs the way you want. There are usually several ways to achieve the same result though and one of them is optimal. I already saw many sub-optimal pipeline out there but there are a few tricks to achieve perfection. :slight_smile:

I’m still not sure exactly what you are trying to do or implement so I might be completely off topic. :confused:

At least I tried :muscle: !

Cheers,
Maxime.

1 Like

Thank you for reply.

I need a way how to calculate that some events are in correct order. For example, we have five events:
a,b,c,d,e
I dont know how to write query, that generated the next :

a - 100%
a → b 50%
a → b → c 30%
a->b->c->d 25%
a->b->c->d->e - 5%

all this events should be in orded as above.
This type of query is called “Conversion rate” or funnel.
Maybe you can helm to understand how to implement such thing using mongodb.

Your example would’t work correct because order of events must be considered too.

Can you provide a few sample JSON documents to illustrate your use case and the expected output that you expect from these docs?

You can insert Markdown code blocks in here like so:

{ _id: 'a', date: ISODate("2022-06-08T19:11:59.221Z") }

Thank you for help. I have done this task using $reduce function from aggregation framework and some code

2 Likes