Forum Moderators: open

Message Too Old, No Replies

Keyword...

How to find what keyword was used to find me...

         

freitasm

2:48 am on Oct 23, 2003 (gmt 0)

10+ Year Member Top Contributors Of The Month



Lots of users get to my site from Google search. How can I find from my .asp script what keywords were used to find me, so I could do a search in my database and present alternative articles as a bonus at the bottom of the page?

Cheers!

wardbekker

6:55 am on Oct 23, 2003 (gmt 0)

10+ Year Member



In the HTTP header you can find the referring url. See [devguru.com...] for HTTP_REFERER.

Parse the name/value pair for the keyword values.

Good luck!

freitasm

7:53 am on Oct 23, 2003 (gmt 0)

10+ Year Member Top Contributors Of The Month



Yep, will look at this... Just have to be carefull to not to waste too much cycles for some unimportant search :(

Server's CPU are not readily available...

Thanks!

aspdaddy

9:39 am on Oct 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone have a regex to parse these queystrings (vbScript)?

Not perfect, but a start..

intStart = instr(1,s,"q=")+2
intEnd = instr(intStart,s,"&")
if intEnd=0 then
intEnd = len(s)+1
end if
intLength = intEnd-intStart

qSearch = trim(mid(s,intStart,intLength))

killroy

9:50 am on Oct 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I only have them for MYSQL, but quote comprehensive:

I've pasted it in this thread:
[webmasterworld.com...]

Cheers

SN

macrost

11:34 am on Oct 23, 2003 (gmt 0)

10+ Year Member



Well the thing now that I have noticed in my logs is this: when users do come from google now, in the referer it only shows say search.google.com? or something like that. Heck even my stats don't show any people coming in from google. well it could also be my stats-ware too, i'm running live stats on a virtual server...

TheDave

12:12 pm on Oct 23, 2003 (gmt 0)

10+ Year Member



I just happened to have written a small keyword parser in vb about 2 days ago - I've cut it down a bit but if you want I can post the full functions including url unencoding and min/max word length

Function GetWords(i as String) as String
dim query_ids()

query_ids = Array("q=", "query=", "p=", "qry=", "string=", "searchfor=", "qkw=", "url=", "va=", "vp=", "key=", "queryterm=", "keywords=", "s=")

o = ""

c = 0
Do While c < UBound(query_ids)
s = query_ids(c)
If InStr(1, i, s) > 0 Then
we = (InStr((InStr(1, i, s) + Len(s) - 1), i, "&") - 1)
If we < (InStr(1, i, s) + Len(s) - 1) Then we = Len(i)
o = Right(Left(i, we), Len(Left(i, we)) - (InStr(1, i, s) + Len(s) - 1))
Exit Do
End If
c = c + 1
Loop

GetWords = o

End Function

If anyone has any search phrase identifiers to add to that query_ids array please let me know! :) I went through 12 months worth of stats to find all them

As a side note, I experimented with testing all referals for "=" and taking the string after that, and testing that for length and whether it contains numbers (which are usually useless stats for me) but that didnt work too good. I got about 9000 phrases from that method as opposed to 11000 for the method demonstrated above. Whats more, the 11000 are all pure, where-as quite a few of the 9000 were bogus or contained bogus elements.

aspdaddy

8:48 pm on Oct 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for that , very usefull - please post the url decoding stuff it would be good to see how its done.

I think what would be rarely good for porting to another analysis tool is to return the data as an array of words, or even better an object with the array of strings and the search engine location (Country id or .com) and the page number.

TheDave

10:15 pm on Oct 23, 2003 (gmt 0)

10+ Year Member



Function UnEncodeURL(ByVal i As String)
Dim a
Dim o
Dim l As Long

On Error GoTo ErrH
o = i

If InStr(1, i, "%") > 0 Then


If Left(i, 1) = "%" Then
a = Split(Right(i, Len(i) - 1) & "%", "%")
c = 0
o = ""
Else
a = Split(i & "%", "%")
c = 1
o = a(0)
End If

u = UBound(a)
While c < u
t = "&H" & Left(a(c), 2)
l = CLng(t)
o = o & Chr(l) & Right(a(c), Len(a(c)) - 2)
c = c + 1
Wend

End If

UnEncodeURL = Replace(Replace(o, Chr(34), ""), "+", " ")

Exit Function

ErrH:

UnEncodeURL = " "

End Function

Function GetWords(i As String) As String
Dim s As String
Dim o As String
Dim t As String
Dim c As Integer
Dim we As Integer

Dim a
Dim m
Dim query_ids()

Const min_word_len = 3
Const max_word_len = 32

m = min_word_len
x = max_word_len

query_ids = Array("q=", "query=", "p=", "qry=", "string=", "searchfor=", "qkw=", "url=", "va=", "vp=", "key=", "queryterm=", "keywords=", "s=")

GetWords = ""

c = 0
Do While c < UBound(query_ids)
s = query_ids(c)
If InStr(1, i, s) > 0 Then
we = (InStr((InStr(1, i, s) + Len(s) - 1), i, "&") - 1)
If we < (InStr(1, i, s) + Len(s) - 1) Then we = Len(i)
o = Right(Left(i, we), Len(Left(i, we)) - (InStr(1, i, s) + Len(s) - 1))
Exit Do
End If
c = c + 1
Loop

'o = ""
'If InStr(1, i, "=") Then
' a = Split(i, "=")
' c = 1
' While c < UBound(a)
' If InStr(1, a(c), "&") > 0 Then
' t = Left(a(c), InStr(1, a(c), "&") - 1)
' If Len(t) >= m Then o = o & t & " "
' Else
' If Len(a(c)) >= m And Len(a(c)) <= x Then
' o = o & a(c) & " "
' End If
' End If
' c = c + 1
' Wend
'End If

o = UnEncodeURL(o)

If Not o = "" And InStr(1, o, " ") > 0 Then
o = SortWords(o)
a = Split(o, " ")
o = ""

c = 0
While c < UBound(a)
If (Len(a(c)) >= m And Len(a(c)) <= x) And NoNumbers(a(c)) = True Then
o = o & a(c) & " "
End If
c = c + 1
Wend
ElseIf Len(o) < m Or Len(o) > x Or NoNumbers(o) = False Then
o = ""
End If

GetWords = LCase(o)

End Function

Function NoNumbers(ByVal i As String) As Boolean
Dim s
s = "0123456789"
c = 0
While c < Len(s)
c = c + 1
If InStr(1, i, Mid(s, c, 1)) > 0 Then
NoNumbers = False
Exit Function
End If
Wend
NoNumbers = True
End Function

Function SortWords(i As String) As String
Dim a

Dim rs_t As Recordset

a = Split(i & " ", " ")

Set rs_t = New Recordset
rs_t.Fields.Append "w", adVarChar, 255
rs_t.Open

c = 0
While c < UBound(a)
rs_t.AddNew
rs_t("w") = a(c)
c = c + 1
Wend

rs_t.Sort = "[w] ASC"
rs_t.MoveFirst

While Not rs_t.EOF
o = o & rs_t("w") & " "
rs_t.MoveNext
Wend

SortWords = o

End Function

Sort words sorts the words in each phrase alphabetically. Probably worth mentioning I am using this particular script in an access database, so you may need to change some stuff like the Recordset object creation for use in an ASP page.