23

I need to test some custom firing events using Google Analytics. I'd like to test in a local environment.

I've set up my test site using apache with server name: my-ga-test.localhost/

According to Can you test google analytics on a localhost address? and Google Analytics docs, I'm able to adjust my GA code to use:

ga('create', 'UA-XXXX-Y', {
  'cookieDomain': 'none'
});

I tried to set up a new account to get a tracking ID for this site, but I'm getting the following error:

URL ends with an invalid top-level domain name

enter image description here

How do I generate the code using localhost domain so I can alter the tracking ID code to put on my localhost?

Community
  • 1
  • 1
user3871
  • 12,432
  • 33
  • 128
  • 268

2 Answers2

44

The "Website URL" field when creating a new Google Analytics property does not have to be the same as the actual URL that's used in production. It's primarily used for resolving relative links, not for validating hits.

Just change it to something else (like example.com), and everything should work fine.

Philip Walton
  • 29,693
  • 16
  • 60
  • 84
4

I do not recommend the above answer.

I believe the best practice is to use the Analytics Debug js on your localhost. Debug prints in console EVERYTHING is doing, including firing events. That way you can check if your code is working or not without sending tracking info to Analytics on Localhost (which makes no sense).

Find out more here :)

JStriedinger
  • 549
  • 1
  • 5
  • 8
  • 2
    This question is specifically about the "Website URL" field when creating a new Account or Property. It has nothing to do with the debug version of `analytics.js` – Philip Walton Dec 12 '16 at 16:28
  • I think he created a test view, in which case is okay to have that for testing. From my experience I got numerous insights from having just a testing view (I do use Analytics Debug js as well). – Mugur 'Bud' Chirica Mar 23 '17 at 18:09
  • And also how do you enter `UA-XXXXX-Y` without going through this step? Analytics Debug JS also needs it – Hafiz Temuri Nov 12 '19 at 15:24