M
M
Maxim Savchenko2014-07-28 23:28:56
Nginx
Maxim Savchenko, 2014-07-28 23:28:56

How to make a redirect to nginx so that it is taken into account by Google analytics as a separate traffic source?

Now the config looks like this:
server {
listen 80;
server_name www.dom1.com
dom1.com
www.dom2.com
dom2.com
;
root /vhosts/dom/www;
index index.html index.htm index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm-dom.sock;
fastcgi_index index.php;
root /vhosts/dom/www;
include fastcgi_params;
}
location / {
set $flag 0;
if ($host = 'www.dom1.com' ) {
set $flag 1;
}
if ($host = 'dom2.com') {
set $flag 1;
}
if ($host = 'www.dom2.com' ) {
set $flag 1;
}
if ($flag = 1) {
rewrite ^/(.*)$ dom1.com/$1 permanent;
}
try_files $uri $uri/ /$uri /index.php?q=$uri$args /mailer.php?q=$uri$args /hecher.php?q=$uri$args;
}
}
Question: how to use Google Analytics to count these domains as different sources, i.e. add query parameters like:
utm_source=dom2.com&utm_medium=redirect"
PS
now analytics considers access to domain2 as a direct access to the main domain.
Question history toster.ru/q/113937?utm_source=email_toster&utm_med...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurph, 2014-07-29
@shurph

The config should look something like this ( you just need to tweak the regular expressions so that cases where get parameters are missing in the original request are handled normally (I left comments in this place in the config)):

server {
  listen 80;
  server_name dom1.com;
  
  root /vhosts/dom/www;
  index index.html index.htm index.php;
  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm-dom.sock;
    fastcgi_index index.php;
    root /vhosts/dom/www;
    include fastcgi_params;
  }
  location / {
    try_files $uri $uri/ /$uri /index.php?q=$uri$args /mailer.php?q=$uri$args /hecher.php?q=$uri$args;
  }
}
server {
  listen 80;
  server_name www.dom1.com;
  location / {
    rewrite ^/(.*)$ dom1.com/$1 permanent;
  }
}
server {
  listen 80;
  server_name www.dom2.com
    dom2.com;
  location / {
    # будет работать, если во всех урлах передаётся какой-то get параметр
    # т.е. оригинальная ссылка толжна быть dom2.com/?smthng=blabla, чтобы
    # получить dom1.com/?smthng=blabla&utm_source=dom2.com&utm_medium=redirect
    # иначе может получится нерабочая ссылка вида dom1.com/page/&utm_source=dom2.com&utm_medium=redirect
    rewrite ^/(.*)$ dom1.com/$1&utm_source=dom2.com&utm_medium=redirect permanent;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question