It's supposed to be done, and in plain Google Universal Analytics, it should be a simple matter of setting the location:
ga('set', 'location', sanitisedLocation);
But in GTM, of course, there is no place in the code snippet where the ga
variable has been created, but the pageview has not been triggered.
So where would I add such code? I'm guessing it might be via the dataLayer
but wouldn't know how, exactly.
Edit: I'd be happy to do this by editing the Pageview tag in the GTM UI, but I don't know where to override the location with a custom variable.
You have 2 options:
<script>
elements.location
and other Google Analytics parameters. You will need to create a variable (eg {{sanitisedLocation}}
as Custom JavaScript to return the value, and use that for your field: