Would be useful to know when a visitor or bot:

  1. Clicks on an item link to view item details
  2. Visits an item detail page

One use case would be:
- Record/log item detail link views or link clicks for later reporting and analysis and visitor analytics

Implementation should allow modules to implement an 'amazon_store_detail_click' and 'amazon_store_detail_page_view' hook handlers.

The 'amazon_store_detail_page_view' hook should allow redirection to another URL and specify the HTTP redirection status code (301, etc). In other words, the hook implementation can override the default behaviour, which is to load the default item details page.

CommentFileSizeAuthor
#3 add-item-lookup-callback-1167688-1.patch1.89 KBmcurry

Comments

rfay’s picture

I kind of think this should be handled already by the Drupal stats module or by webserver logs?

mcurry’s picture

Priority: Normal » Minor
Status: Active » Postponed (maintainer needs more info)

Well, perhaps in the use case I listed. I have another use case that isn't handled by the current Drupal stats. I'd like to record visited ASINS and do some background processing on all recorded ASIN visits. I *can* do that by examining the visitor logs, but redirecting to another page instead of the detail page isn't so easy (I suppose I could use lower-level Drupal hooks for that).

Let me think about this for a while. Marking as postponed pending more info.

mcurry’s picture

Title: Item Detail click/view tracking capability » Provide hook 'amazon_store_item_lookup' on successful item retrieval from Amazon
Priority: Minor » Normal
Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new1.89 KB

Changing title to reflect what I *really* wanted. :D

Here's what I'm after.

In the simplest case, let's say I want to generate concise logs about the ASINs users look up on my Amazon Store. Sure, I could scour log files, intercept page views and examine URLs, etc. but why should I have to go through all that trouble?

For a more complex case, let's say I want to build an Amazon Store contrib module that collects info on all Amazon item lookups through the Amazon Store module.

Why would I want to do that?

I'd like to gather and analyze information that's contained in the item lookup response, for later use in the site's Amazon store. Let's say (for example) I want to build a dynamic store that shows related categories and products in a more intelligent way (or at least, different from the way Amazon's related products works).

One way for me to do this is to analyze certain information returned from the successful ItemLookup operation when it is retrieved from the Amazon server. (Yes, I know about the Amazon guidelines on caching data; I'm not going to violate their guidelines and neither should you.)

But, I can't do this easily without a notification when the ItemLookup operation succeeds. I *could* scour the cache table periodically, looking for new entries, but that's a hack and grossly inefficient. Much easier to receive a notification when the item retrieval takes place. And it's very simple to implement in amazon_store_get_item_data(). Just add a call to module_invoke_all():

 if (!empty($amazon_item)) {
    amazon_store_cache_item($amazon_item);
    //
    // Give other modules a look at the data.
    // At present, we ignore the hook implementations' return value.  This
    // may change in the future (perhaps to allow modification of the result).
    module_invoke_all('amazon_store_item_lookup', $asin, $parameters, $results);
  }

Works like a charm.

I don't see this as a major performance or reliability issue unless hook implementers are careless. But that's the case with all hook implementations, isn't it?

6.x-2.x-dev patch attached.

rfay’s picture

You're only giving them a shot at the data when it's not cached... Is that what you want?

I think this should be OK as a basic approach.

mcurry’s picture

@rfay:

You're only giving them a shot at the data when it's not cached... Is that what you want?

Yes, that's exactly what I am proposing, because I can see a distinct use case where clients only want to know about new lookups as they occur (as is the case in my store).

I can see a use case for getting a callback on every lookup whether cached or not, but that could be a separate callback.

I anticipate (and will propose) additional callbacks for the other API lookups, which will be described in separate issue(s); this was my first cut since I have a direct need for this one now.

mcurry’s picture

@rfay: Any objections to me committing this mod? I'll have to port it to the D7 branch...
(I'm itching to try out my new commit access :D )

rfay’s picture

Works for me. I was hoping to see code that exercised it first, but go for it.

You may want to make a sample logging module that ships with this, if it's useful, that could listen on the hook.

mcurry’s picture

Good idea. I'll build a module that listens to all of the hook(s) we might end up implementing.

I am exercising the code in my (in-development) store module(s), thought that's not exactly heavy testing :D

The main reason I want to commit is that I don't want to accumulate too many local changes on my local filesystem... I'm new to Git but I'm in the habit of committing often when the changes stand alone.

mcurry’s picture

I can build the exerciser module and commit it with this patch. Time to bone up on Git...

mcurry’s picture

Status: Active » Patch (to be ported)

I've committed the new test module and the modified amazon_store.module file. Sadly, it took two commits, since somehow I missed the amazon_store.module on the first commit.

Commit 62e5f7a on 6.x-2.x
by mcurry

Issue #1167688 by mcurry: Add hook 'amazon_store_item_lookup' in amazon_store_get_item_data. This provides a notification whenever an ASIN's data is retrieved from Amazon servers. This commit adds a file that was missing from the prior commit.

Amazon Store: May 26, 2011 19:58
Commit 449d8b6 on 6.x-2.x
by mcurry

Issue #1167688 by mcurry: Add hook 'amazon_store_item_lookup' in amazon_store_get_item_data. This provides a notification whenever an ASIN's data is retrieved from Amazon servers.

mcurry’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev

Fixing Version (since it's a patch to be ported)