'Helper method to publish events for analytics purposes'

def _publish_events(self, block_structure, location, previous_count, max_count, block_keys, user_id):

    def format_block_keys(keys):
        '\n                                                Helper    function    to    format    block    keys\n                                                '
        json_result = []
        for key in keys:
            info = block_structure.get_transformer_block_field(key, ContentLibraryTransformer, 'block_analytics_summary')
            json_result.append(info)
        return json_result
    def publish_event(event_name, result, **kwargs):
        '\n                                                Helper    function    to    publish    an    event    for    analytics    purposes\n                                                '
        event_data = {'location': unicode(location), 'previous_count': previous_count, 'result': result, 'max_count': max_count}
        event_data.update(kwargs)
        context = contexts.course_context_from_course_id(location.course_key)
        if user_id:
            context['user_id'] = user_id
        full_event_name = 'edx.librarycontentblock.content.{}'.format(event_name)
        with tracker.get_tracker().context(full_event_name, context):
            tracker.emit(full_event_name, event_data)
    LibraryContentModule.publish_selected_children_events(block_keys, format_block_keys, publish_event)
