Improved tracking URL generation to handle spaces in tracking numbers

Fixes #4233
use AR 4 syntax or prefix table name on some scopes

Fixes #4225