public function action_executed($actionname, \core_analytics\local\target\base $target) {
        global $USER, $DB;

        $context = \context::instance_by_id($this->get_prediction_data()->contextid, IGNORE_MISSING);
        if (!$context) {
            throw new \moodle_exception('errorpredictioncontextnotavailable', 'analytics');
        }

        // Check that the provided action exists.
        $actions = $target->prediction_actions($this, true);
        foreach ($actions as $action) {
            if ($action->get_action_name() === $actionname) {
                $found = true;
            }
        }
        if (empty($found)) {
            throw new \moodle_exception('errorunknownaction', 'analytics');
        }

        $predictionid = $this->get_prediction_data()->id;

        $action = new \stdClass();
        $action->predictionid = $predictionid;
        $action->userid = $USER->id;
        $action->actionname = $actionname;
        $action->timecreated = time();
        $DB->insert_record('analytics_prediction_actions', $action);

        $eventdata = array (
            'context' => $context,
            'objectid' => $predictionid,
            'other' => array('actionname' => $actionname)
        );
        \core\event\prediction_action_started::create($eventdata)->trigger();
    }