Search code examples
phpjavascriptsearchseo

Display Google Keywords that brought a user to the site


I am looking to display something like:

Hello, you've reached this site by looking for [google keyword(s)]

I'm pretty sure I've seen this done before but I am having troubles figuring out how to grab the keywords that were used to lead a user to my site. Anyone know the answer?


Solution

  • You need to get the referring URL and then strip out everything for the "q" query string. This will give you the query that was used to get you to your page.