Add publish event function, but has errors.