Being code that is running in the context of a layer you have 2 options: check by template or check by request. Requests are unique while templates are sometimes shared among some group of pages.
A simple way to see the template would be adding this code inside the initialize() function:
echo $this->template;
In order to see the request you could use:
echo qa_request(); // Or also echo $this->request;
You can access specific parts of the request by using qa_request_part() function.
Once you have identified the template or request you want your code to execute on, then you could just check this way:
public function initialize() {
parent::initialize();
if ($this->template === 'question') {
echo 'this code will only run in the "question" page';
}
}