def getRegistrationReferralCounts(startDate,endDate):
    '''
    When a user accesses the class registration page through a
    referral URL, the marketing_id gets saved in the extra JSON
    data associated with that registration.  This just returns
    counts associated with how often given referral terms appear
    in a specified time window (i.e. how many people signed up
    by clicking through a referral button).
    '''

    timeFilters = {}
    if startDate:
        timeFilters['dateTime__gte'] = startDate
    if endDate:
        timeFilters['dateTime__lt'] = endDate

    regs = Registration.objects.filter(**timeFilters)
    counter = Counter([x.data.get('marketing_id',None) for x in regs if isinstance(x.data,dict)] + [None for x in regs if not isinstance(x.data,dict)])

    results = [{'code': k or _('None'), 'count': v} for k,v in counter.items()]
    return results
When a user accesses the class registration page through a
    referral URL, the marketing_id gets saved in the extra JSON
    data associated with that registration.  This just returns
    counts associated with how often given referral terms appear
    in a specified time window (i.e. how many people signed up
    by clicking through a referral button).