0

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?

2
  • You want to track multiple domains within one GA property?
    – XTOTHEL
    Oct 23, 2018 at 2:53
  • Correct. It’s the same app that has multiple domains pointing to the server. My app logic figures out what to serve.
    – Zach
    Oct 23, 2018 at 3:02

1 Answer 1

1

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?

2
  • Hm, that is pretty interesting. Thanks for the filter example, but yeah since I'll be consuming the API; I guess it wouldn't be that big of a deal to create a filter. Thanks for the heads up!
    – Zach
    Oct 24, 2018 at 0:06
  • I created a follow up question in case anyone has a moment to look at that; stackoverflow.com/questions/53211634/… thanks!
    – Zach
    Nov 9, 2018 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.