如何在Wordpress中添加Googles utm_source变量?

时间:2012-11-05 13:42:51

标签: php wordpress .htaccess google-analytics utm

我在wordpress中使用永久链接结构,如www.domain.com/sample-post/,但它自然会阻止它不知道的所有参数。

我实际上只想将Googles ?utm_source=变量添加到某些链接以跟踪某些来源,但Wordpress会阻止它们,并且在我的日志中输出/none时出现404错误。

你知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

而不是使用?您可以选择使用#来传递utm_source值。

要执行此操作,只需将此行添加到_trackPageview上方的分析跟踪代码即可       _gaq.push(['_ setAllowAnchor',true]);

现在您可以像这样标记utm_source参数 http://mysite.net/index.html#utm_source=Source&utm_medium=email&utm_campaign=Name

由于#ent传递给服务器之后的数据,wp会继续看到相同的网址

答案 1 :(得分:0)

# Block the include-only files. 
RewriteEngine On
RewriteBase /
# RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L] 

# Preventing Directory Listing, Leads to Block and 403 and 401
Options -Indexes

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress

我使用domain.com/sample-post/作为永久链接结构