1

I have an nginx server and a site.erb file and two different domains (domain1 and domain2). Currently a tag (for Google Tag Manager) will be set when someone visits the sites from a particular set of remote IP addresses (set $analytics "'userType': 'internal'") and this info is sent to Google Analytics:

# Set userType variable for Google Tag Manager (default is external)
set $analytics "'userType': 'external'";

# LAN traffic is internal therefore,
if ($remote_addr = zzz.zzz.zzz.zzz) {
  set $analytics "'userType': 'internal'";
}

# The Wifi traffic is internal therefore, 
if ($remote_addr = yyy.yyy.yyy.yyy) {
  set $analytics "'userType': 'internal'";
}

sub_filter "'userType': 'external'" $analytics;

Now the task is to have one set of IP addresses tagged as internal when visiting domain1 and a different set of IP addresses tagged as internal when visiting the different vhost domain known as domain2.

Is there a way to do this with embedded ruby files (site.erb) or is there a way that Nginx can do this and set it as a parameter in the site.erb file. I am not very familiar iwth nginx or with embedded ruby so a simple explanation as to how would be great.

I am thinking something like the following might work but not sure if server_name in nginx is a viable variable or not:

server_name= Something_Something

Extraction = (Extract from server_name variable domain1.com part OR domain2.com part depending on what it is)

domain1_internal_ip_array=a.b.c

domain2_internal_ip_array=x.y.z

set Analytics == external

if Extraction == domain1.com AND remote_ip == domain1_internal_ip_array then Analytics == internal

if Extraction == domain2.com AND remote_ip == domain2_internal_ip_array then Analytics == internal

Castaglia
  • 3,349
  • 3
  • 21
  • 42
tomhafiz
  • 11
  • 1

0 Answers0