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?

4
  • Is there another plugin that would possibly catch that utm_source parameter before your own code runs? Commented Dec 29, 2017 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. Commented Dec 31, 2017 at 2:35
  • 1
    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. Commented Dec 31, 2017 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. Commented Jan 2, 2018 at 16:06

1 Answer 1

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.

3
  • Tech support could provide no detail. Wow, that sounds frustrating. Glad you were able to track it down, though. Commented Jan 2, 2018 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.) Commented Jan 4, 2018 at 4:05
  • It appears to be not just utm_*; utm___source (multiple underscores) works fine! But why? Commented Jan 4, 2018 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.