views:

193

answers:

6

I have a quick question i hope you guys can answer, i've got a search system that uses POST to do searches, now i want to track queries using Google Analytics but it requires using GET url parameters to pull parameters out the URL, what i don't want to do is rewrite the entire search system to use GET instead of POST. Is there any way around this? I was thinking maybe i can make a GET call to a new page from the page that recieves the search POSTs, but i don't want it to redirect, i merely want it to "hit" the url without actually redirecting?

Is this possible?

Any other solutions would also be appreciated.

Thanks for the help

A: 

Sure, use the apache mod_rewrite module to create a fancy, seo friendly url and pass the user keywords in the url.

Something like "www.yoursite.com/search/what+a+user+searches+for/"

In a .htaccess file you create a rule RewriteRule ^search/(.*)/$ /search.php?keywords=$1

You're orignal script keeps working with your postvalues and you provide an URL with GET variables. With explode("+", $_GET["keywords"]) you can extract the searchvalues.

Ben Fransen
A: 

With the array $_REQUEST you can access all request parameters GET and POST.

rogeriopvl
But he wants to get analytic data, so he has to provide a new url, so in this scenaria $_REQUEST won't suit.
Ben Fransen
Yes you're correct. I misinterpreted the question.
rogeriopvl
A: 

The only way you will be able to do this, is re-set the forms method to GET and just changed the $_POST requests to $_GET

Thats not such a huge change?

Pino
A: 

You should be able to do that with HTTPRequest:

http://php.net/manual/en/class.httprequest.php

Pesse
A: 

You can just alter your Google Analytics code - see Tracking Custom Variables

Greg
A: 

You can specify an abritrary URL when you add your GA code. For example, all our different checkout pages go through validate.php, so this is the URL that the person would see, however, we put in some extra code to give a specific tracking URL to google.

For example:-

<script type="text/javascript">
    try {
        var pageTracker = _gat._getTracker("UA-XXXXX-1");
        pageTracker._setDomainName("example.com");
     pageTracker._trackPageview("/checkout/login/");
    } catch(err) {}
</script>

Would make google track this as being /checkout/login/ even though the page in the browser actually shows /validate.php

You can output (as we do) this page variable from different PHP variables

$searchterm = $_POST['search'];
echo 'pageTracker._trackPageview("/search/' . urlencode($searchterm) . '");';
Mez