Zach
Zach

Reputation: 1185

Google Analytics - (gtag) One tracking code, multiple domains

I've been reading through a few questions/answers around using one tracking code and setting up custom dimensions to capture other domains. My use-case is an app that can have items with a custom domain mapped to them; which still get sent to my server, recognized, and then show as the custom item. I'm using gtag instead of ga as some of the examples I've been reading do. If I want to use the same tracking ID and then use the Google Analytics API to grab statistics for a certain domain, have any suggestions on how I'd set that up? A little confused on the best way to do that. Thanks!

Clarification

Since these domains are setup by the client; I'd ideally like to have this done in an automated way so the API can grab the data automatically.

I noticed I can set persistent values but how would I go about filtering this in the admin?

Upvotes: 0

Views: 723

Answers (1)

XTOTHEL
XTOTHEL

Reputation: 5208

I don't think you need to do anything additional in terms of implementation of the gtag.js on your site. Just leave the default gtag.js that's provided to you by GA on your app.

What you need to do is some configuration in GA, specifically view filters.

You will need to create a filter based on:

Filter Type: Custom filter > Advanced
Field A: Hostname
Extract A: (.*)
Field B: Request URI
Extract B: (.*)
Output To: Request URI
Constructor: $A1$B1

When you do the above, all the content reports will show full url including domain name in GA. You can then use the analytics API to query for it.

Also note, if you don't do any configuration, you can still look up the "hostname" dimension and combine that with the "page" dimension. Together they will tell you on what domain the page view was for.

Reference: https://support.google.com/analytics/answer/1012243?hl=en

I do have to say, having multiple domains tracked on one property is an odd way of doing things. Can you not vary the property id as well depending on the domain in your app?

Upvotes: 1

Related Questions