Mobile app version of vmapp.org
Login or Join
Ogunnowo487

: How to secretly rewrite Google Analytics campaign codes to main page? I want to create a simple "secret" mod_rewrite redirect (not shown in user's browser address box) to redirect: http://www.mydomain.com/code

@Ogunnowo487

Posted in: #GoogleAnalytics #ModRewrite #UrlRewriting

I want to create a simple "secret" mod_rewrite redirect (not shown in user's browser address box) to redirect:
www.mydomain.com/code -> www.mydomain.com/?utm_source=redirect&utm_medium=link&utm_campaign=code

And if possible also add if missing, so:
mydomain.com/code -> www.mydomain.com/?utm_source=redirect&utm_medium=link&utm_campaign=code

I tried:

# Custom rewrites
RewriteRule ^code/?$ /?utm_source=redirect&utm_medium=link&utm_campaign=code [L,NC,QSA]


My .htaccess mod_rewrite other rewrite rules look like this:

# redirect to www form
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} !^([a-z]+).%{HTTP_HOST} [NC]
RewriteRule ^(.*)$ www.%{HTTP_HOST}/ [R=301,QSA]
# rewrite file to file.php, ignore directories, ignore existing non-php files
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) .php [L,QSA]


I tried to put the custom rewrites section either in front of all the other rules or in the middle or remove [QSA]/[NC], but the problems are that it either


Doesn't rewrite secretly
Doesn't show rewrites in Google Analytics (I'm sensing it's because it does some other rewrite before and therefore Google Analytics won't count the campaign)


What am I doing wrong?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ogunnowo487

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

It looks like it is not possible to do the redirect using mod_rewrite as it is processed before the page even starts loading and Google Analytics is JS which is fired only after the page starts loading.

BUT it is possible to create a JS redirect called after Google Analytics pageview has been tracked.

I have found more about that at this article: cfsimplicity.com/61/removing-analytics-clutter-from-campaign-urls

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme