0

There are several ways I have seen this question worded, so I tried to make mine generic.

Let's say I go to this page:

example.com/page/?utm_source=test&s=test&page=12

get_query_var('utm_source') returns nothing.

$_GET returns Array ( [s] => test [page] => 12 ).

$_GET returns Array ( [utm_source] => ) from example.com/page/?utm_source (key only, no value), which I really don't understand.

I've done this in functions.php:

add_filter( 'query_vars', 'add_query_vars_filter' );
function add_query_vars_filter( $vars ){
    $vars[] = "utm_source";
    return $vars;
}

...just like ye olde codex says, so I would expect to be able to access utm_source through get_query_var('utm_source'). What am I missing?

  • Is there another plugin that would possibly catch that utm_source parameter before your own code runs? – Alexis Wilke Dec 29 '17 at 22:34
  • Perhaps, but my question is more about the fact that I'm going by the book as far as I know, with unexpected results. – adam rowe Dec 31 '17 at 2:35
  • Thinking about it, if it's not in the $_GET something must be removing it really early. Maybe there is something in your Apache/PHP install that will remove those utm_... early on. What I would try is to write the $_GET variable in the index.php (so super early on) and also search all the files in your plugins for the string utm_ to see whether other plugins handle those variables. – Alexis Wilke Dec 31 '17 at 22:30
  • 1
    I had already looked & checked again for anything server-side which might be interfering. No plugins are being used. Also, see edit to original question: utm_source key is in $_GET when utm_source is empty. – adam rowe Jan 2 '18 at 16:06
4

The answer to my general question has a very specific answer, and I found the answer by running across this answer to more or less the same problem. Basically GoDaddy hosting does something special to utm_-type query strings. Tech support could provide no detail.

In case anyone else runs across this, it looks like something mysterious happens to the standard Google Analytics query strings such as utm_source. Example: utm_source will not show up in $_GET (much less using get_query_var), but utm__source (2 underscores) is just fine.

  • Tech support could provide no detail. Wow, that sounds frustrating. Glad you were able to track it down, though. – Pat J Jan 2 '18 at 17:42
  • Ah, so it is before you hit your PHP. They may have a form of proxy server and the proxy-ing server will removes utm_* variables before your server is hit. I would never have thought of such done by a hosting company. On my end I'm using DigitalOcean and get everything through "no problem." (except that includes all spam/hacker hits too.) – Alexis Wilke Jan 4 '18 at 4:05
  • It appears to be not just utm_*; utm___source (multiple underscores) works fine! But why? – adam rowe Jan 4 '18 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.