Задать вопрос

Тел: +7 965 3737 888





Middleware to detect visitors who arrived from a search engine

<p>Sometimes it's nice to know if your visitors came from a search engine such as Google or Yahoo. I use this as a component in determining the popularity of blog articles for search keywords, so I know which articles to automatically feature or suggest. Maybe you'd like to use it to highlight the visitor's search terms on the page.</p>
<p>This isn't actually middleware in the sense that it defines any of the middleware interfaces. It's intended to be the base for a middleware method that you write, depending on what you want to happen when you detect that the visitor came from a search engine. In the example process_view method, I detect when the request is going to use the object_detail view and log the search query for that object in the database.</p>

Вопрос полезен? Да0/Нет0

Ответы (5):

Ответ полезен? Да0/Нет0

How to use this code ? And I need to google referrer code.

Ответ полезен? Да0/Нет0

We've been using this and after a very long and painful bug hunt have discovered there are couple of tweaks you might want to make.

You'll probably want to edit line 44 to make it "parse_qs(unicode(query))" and line 46 to make it "u' '.join" otherwise you may spend a while trying to work out why your template is throwing a DjangoUnicodeError!

Ответ полезен? Да0/Нет0

Thanks, this worked nicely.

Ответ полезен? Да0/Нет0

@zenx: Fixed, thanks!

Ответ полезен? Да0/Нет0

On line 42 replace: match = re.match(NETWORK_RE % engine, network)

with: match = re.match(cls.NETWORK_RE % engine, network)