Hi Gijs,

> I have been trying different approaches to achieve this by using a custom map 
> and reduce function.

My rule of thumb is to avoid custom reduce functions at all cost.
Maybe it's a bit harsh but it saved me a lot of time and frustration.

>>> Now i want to do very mailchimp/campaignmonitor like summary per campaign 
>>> (key[3}) that show nr of unique delivers, nr of unique opens, nr of unique 
>>> clicks.
> SELECT count(*) FROM events WHERE type='click' GROUP BY contact_id;
> But i want the single view to output both the unique clicks, views and opens


First, you should emit the following keys (in this order, with no value):

    [campaign, type, contact_id]

Then you can reduce those data (with any builtin reduce function, `_count` for 
example) and `group=true` (which is shorter than 
`reduce=true&group_level=exact`).

Then you'll need an other computation round to count unique contacts (per 
campaign and type). While waiting for chained map-reduce (coming soon I hope), 
you can cheat and do it with a list. 
With a list, it is usually a good idea to send the results as soon as you know 
them (i.e., in this case, when there is a new `type` in the current row or when 
there are no rows anymore).  


Regards,

Aurélien


Reply via email to