Question

Setting up environments

  • 25 July 2023
  • 1 reply
  • 667 views

I have two websites, dev.mysite.com and prod.myside.com.

I want events from dev.mysite.com to be registered in my Amplitude project as development events. prod.mysite.com events, obviously, go as Production events. 

They will use same api key, as it looks like Amplitude sets dev and prod projects. Yet, how do I initialize my @amplitude/analytics-browser to know which environment should be used for the events? I want to explicitly tell the environment.


1 reply

Userlevel 5
Badge +9

Hi @Nuno Cardoso. The setup you’ve described sounds very much like “views” that were in Google’s Universal Analytics, i.e., you could have a single data “property” (mysite) with multiple views (dev, prod, etc). Amplitude doesn’t have this concept, but you can still get to a similar place.

You’ll need two separate Amplitude Analytics projects, say “mysite prod” and “mysite dev”. Then over in Amplitude Data you can create a single data schema with “prod” and “dev” environments respectively pointing at the “mysite prod” and “mysite dev” Analytics projects. I’d then recommend you go to the data schema settings and set the “dev” environment to allow everything in, but set the “prod” environment to reject unexpected Event Names/ Event Properties/ User Properties. You don’t have to do this, but I’ve found doing so is great for data cleanliness in the “mysite prod” project as nothing will go into it until someone has specifically allowed in it through addition to the data schema.

In terms of passing events from the sites, simply use the API key for “mysite prod” on the prod site, then the API key for “mysite dev” on the dev site(s).

As I mentioned, this isn’t quite the same as “views”, but it isn’t too far off. One thing of note is that when you create any derived properties, custom metrics, etc in one of the Analytics projects, you’ll have to repeat that creation in the other project. It’s super annoying that there’s currently no copy-paste mechanic available to make this more efficient, to that end I’ve created a request to Amplitude’s product team for this which you can upvote:

Hope this helps, the below article may also prove useful to you for further info on using Amplitude Data:

https://help.amplitude.com/hc/en-us/articles/5078848559259-Configure-and-manage-your-Amplitude-Data-settings

Reply