The best would be switching to text transformation and use the current page - e.g. CurrentPageInfo macro which gets cached. So you can get the {%CurrentPageInfo.NodeSiteID%} value from cache and if you do not have hundreds of sites, you can use simple macro condition. Or, you can also use {%CurrentDocument.Site.SiteDomainName%} - but this is not in the page info cache, so there are calls made to the DB.
Or, if you are using linked pages from other sites, again using macros is easier and instead of creating custom ASCX transformation methods, you could have already rewritten the code to text transformation and use macros:
{% CurrentDocument.NodeLinkedNode.NodeOriginalNode.Site.SiteDomainName #%}
and others...