The user can control it themselves from their "Privacy options" here.
You cannot control it on behalf of the user. If the user choses to hide their online status or their activity then forum staff who have the "Bypass user privacy" permission can still see it.