               userEventMap[doc.user] ?= []
               userEventMap[doc.user].push doc
             else
-              log.debug 'Analytics finished received docs, closing db connection. ' + Object.keys(userEventMap).length
               db.close()
               for userID, eventList of userEventMap
                 finishedPurchase = false

      debugInvoiceCount = @invoices.length
      @invoices = _.uniq @invoices, false, 'invoiceID'
      if debugInvoiceCount isnt @invoices.length
        log.debug "Analytics cached @invoices hadd duplicates: #{debugInvoiceCount} #{@invoices.length}"

      subMap = {}
      for invoice in @invoices

      try
        # Get conversion data directly from analytics database and add it to results
        url = "mongodb://#{config.mongo.analytics_host}:#{config.mongo.analytics_port}/#{config.mongo.analytics_db}"
        MongoClient.connect url, (err, db) =>
          if err
            log.debug 'Analytics connect error: ' + err
            return @sendDatabaseError(res, err)
          userEventMap = {}
          events = ['Finished subscription purchase', 'Show subscription modal']
          query = {$and: [{user: {$in: subscriberUserIDs}}, {event: {$in: events}}]}
