add support for both window and document

@amillet89 maybe something like this?

https://github.com/segmentio/analytics.js-integrations/issues/416