Lucas Castellani Lucas Castellani - 2 months ago 15
Javascript Question

Pass root domain to JS Script

I want to replace facebook.com with my root domain

<script>
ga('require', 'linker');
ga('linker:autoLink', ['facebook.com']);
ga('send', 'pageview');
</script>


How can I get the root domain where this code is installed and replace facebook for it?

Answer

The window.location object has many properties including hostname

If I understand you correctly you want:

ga('linker:autoLink', [window.location.hostname]);

On this page for example it would return "stackoverflow.com"