'Emit an analytics event with the given name for this Order. Will iterate over all associated
OrderItems and add them as products in the event as well.'

def _emit_order_event(self, event_name, orderitems):

    try:
        if settings.LMS_SEGMENT_KEY:
            tracking_context = tracker.get_tracker().resolve_context()
            analytics.track(self.user.id, event_name, {'orderId': self.id, 'total': str(self.total_cost), 'currency': self.currency, 'products': [item.analytics_data() for item in orderitems]}, context={'ip': tracking_context.get('ip'), 'Google    Analytics': {'clientId': tracking_context.get('client_id')}})
    except Exception:
        log.exception(u'Unable    to    emit    {event}    event    for    user    {user}    and    order    {order}'.format(event=event_name, user=self.user.id, order=self.id))
