Link to product details in an aStore iframe

It’s easy to link to product detail pages in a standalone Amazon store, or to use the target attribute with a custom navigation menu on the same web page as an aStore iframe. But what if you have several product reviews on various pages of your site, and want to link to their product detail page inside your Amazon store iframe?

This question was asked twice in one week on a discussion board I frequent, so, out of curiosity, I decided to figure out a simple way to do it with web pages and with a WordPress blog. First, the target attribute cannot be used with links on different pages than the iframe. The iframe’s src attribute must be changed to load a different page. Fortunately, we can do that with a script. I used jQuery for my ASP.Net website and PHP for WordPress. You could also use JavaScript without the jQuery library or ASP.Net, depending on your site requirements.

Anatomy of an Amazon Store iframe

The generated aStore iframe contains the basic information needed to embed your store on a typical web page with a wide content area:

<iframe src="http://astore.amazon.com/affiiateID" width="90%" height="4000" scrolling="no" frameborder="0" /></iframe>

Most Amazon associates modify the basic iframe to use all available horizontal space in a content div, reduce the height to 1000 or 1200px, and set scrolling to auto, so that a vertical scrollbar can appear when needed. In order to access the iframe via the target attribute, it needs an id and name. To manipulate it with a script, an id is necessary:

<iframe id="astore" name="astore" src="http://astore.amazon.com/affiiateID" width="100%" height="1200" scrolling="auto" frameborder="0"/></iframe>

Link format

Links to product detail pages on a standalone aStore are in this format:

<a href="http://astore.amazon.com/affiliateID/detail/ASIN">Displayed Product Text</a>

Deep links into an embedded iframe go to the page containing the iframe and include a parameter for the ASIN, or product ID number:

<a href="http://astore.amazon.com/affiliateID?azdp=0123456789">Displayed Product Text</a>

The "azdp" parameter is so named to prevent any conflict with WP’s own parameters. That’s why we can’t use a simple "p" for "page".

WordPress Solution

First, create a custom page template for the aStore to get rid of the sidebar(s), unless you have a very wide WP template. A full-width aStore needs about 800px of horizontal space. To do this, save your page.php file under a new name, such as store.php. You need access to the file system via your web host’s CPanel or FTP to do this. Edit the store.php file in your favorite editor or in your WordPress Dashboard, Appearance, Editor panel.

At the top of store.php page, add this code to identify the template:

<?php
/* Template Name: AStore */
?>

Inside the WP template "Loop," I added a short block of PHP code to grab a parameter named azdp from the URL’s query string. If the parameter exists, the script writes a modified astore iframe tag to the store page. If it does not exist, the standard astore iframe tag is written to the page. The param "azdp" contains the ASIN. You can name it anything you want, but WP uses “p” for page, so use something else to avoid conflicts:

<?php
if (isset($_GET['azdp'])) {
$dp = $_GET['azdp'];
echo "<iframe src='http://astore.amazon.com/AffiliateID/detail/$dp' width='100%' height='1200' frameborder='0'></iframe>";
} else {
echo "<iframe src='http://astore.amazon.com/AffiliateID' width='100%' height='1200' frameborder='0'></iframe>";}
?>

Replace AffiliateID with your own AffiliateID or the trackingID you are using with the store. Links that go to the aStore page on this blog would look something like this:
<a href="http://greenetea.com/real-tea/?azdp=B0032A8P2K">Japanese Izu Matcha</a> Japanese IzuMatcha

Finally, edit the Page with the aStore and select the AStore template (or whatever you named it) from the template dropdown on right side of the editing screen. If the page already contained an aStore <iframe> tag, delete it. The page works fine without any content. Remember that your iframe is written to the page by PHP in the aStore page template. If you forget and leave it in place, the astore will be rendered twice.

The main issue I see with this method is that the browser’s address bar does not change as visitors click around in the aStore. It wouldn’t anyway, but with the additional parameter, the URL shown in the address bar might be a little confusing.

jQuery Solution

jQuery works nicely with non-blog websites that are not primarily coded in PHP. If you do not already have it, add the jQuery library to your website and call it using a <script> in the <head> tag of the webpage containing the aStore, or in your site template. Get the jQuery plugin "getUrlParam" by Mathias Bank.

Paste the (preferably minified) script into a javascript file, such as geturlparam.js and call it using a <script> tag in the <head> of the web page containing the aStore or in your template, after jquery.js.

Next, on the web page containing the aStore iframe, add the following script. The script does not try to change the src of the iframe (which must have an id) unless there is a query string in the URL containing the parameter named "p". You can name the parameter anything you want, as long as you adjust the script. The value of the “p” param is Amazon’s product ID number, or ASIN:

<script type="text/javascript">
$(document).ready(function(){
var newSrc = $(document).getUrlParam("p")
if (newSrc !== null) { 
$('#aStore').attr('src','http://astore.amazon.com/affiliateID-20/detail/'+newSrc);
} })
</script>

Links that go to your web page with the aStore follow this pattern:

<a href='http://astore.amazon.com/affiliateID-20?p=ASIN>Good Book</a>

Here's an example link that goes to a demo aStore on one of my websites:
http://greeneteapot.com/2009/09/very-narrow-amazon-store.html?azdp=1601381255

Test on your Site

I am not absolutely certain that nothing bad happens to sessions or cookies, if you use the deep links, but I doubt it, since other people create their own navigation system with aStores. The links themselves seem to work just fine.

Share

13 comments to Link to product details in an aStore iframe

  • This can be a good post. I will surely be reading this blog additional.

  • thanks for good info…I’m working on building astore now…Your info is helpful

  • Kam

    Wow.. Finally I have got what I was looking for.

    Thank you so much author. I would recommend you to use some mor tags like “passing parameters in URL” or Astore and WP, etc.

    I wanted to use same concept in my site and now I can do it. Thanks once again.

  • Is all of this possible to do on a wordpress.com blog or only on a wordpress.org blog? Thanks for the article.

  • The information is useful only for wordpress.org sites. WordPress.com users have limited access to code, and affiliate links are generally not allowed. See WordPress.com’s information about Types of Blogs to see what is acceptable. If you get a site with a web host, and put a wordpress.org blog on it, you have access to your theme templates, and are free to place ads on your site if you wish.

    Blogger is not as versatile as WordPress, but is tolerant of Adsense and Amazon ads, so that’s a possibility if you need free hosting.

  • Di

    Thanks a Million for the info. Saved me tons of grief :)

  • Thanks a lot … greatful thanks for sharing this valuable advance code knowledge like this … so i can make develop my blog more on more.

  • cts

    This was really helpful for adding deep links to my aStore products through my blog posts — do you know if there are any other parameters besides azdp? For example, if I could get a parameter that would send users to a particular category of my store, that would be pretty helpful as well.

  • Hi, cts,

    You can add another parameter to the script, as shown below. There should be no line breaks in the echo statements. If you copy the code and paste to a text editor, the lines will be written properly.

    I’m glad your question caused me to go look at the store page because the custom page template got trashed in one of my theme upgrades. I redid an AStore page template and inserted the following code (with my own AffiliateID) as the first thing in the WP loop:

    <?php
    if (isset($_GET['azdp'])) {
    $dp = $_GET['azdp'];
    echo "<iframe src='http://astore.amazon.com/AffiliateID/detail/$dp' width='100%' height='1200' frameborder='0'></iframe>";}
    else if (isset($_GET['azcat'])) {
    $cat = $_GET['azcat'];
    echo "<iframe src='http://astore.amazon.com/AffiliateID?_encoding=UTF8&#038;node=$cat' width='100%' height='1200' frameborder='0'></iframe>";
    } else {
    echo "<iframe src='http://astore.amazon.com/AffiliateID' width='100%' height='1200' frameborder='0'></iframe>";}
    ?>

    To load the Black Tea category as the aStore iframe src, I would use this link:
    Black Tea

    The code could be made more efficient, but it will work and is understandable.

  • cts

    Awesome, thanks! Your store looks great. For my needs I wanted to add some text and AdSense at the top of the store page, so I just added everything to the end of the loop and everything worked perfectly.

    Are all of your aStore clicks showing up in your full summary page? I’ve got a few random Amazon widgets in blog posts and clicks on those are all showing up just fine in the summary, but it doesn’t appear that aStore clicks are showing up (certainly I have been clicking on things a ton as I tweak the design and inventory). Just want to make sure I am receiving commission for anything I ship. I sent Amazon an e-mail a few minutes ago and will let you know what I hear.

  • You’re welcome! Amazon doesn’t count clicks within the aStore. That’s the way it’s always been, as far as I know. You will definitely get sales credit for orders and see earnings when items ship.

  • Eric

    Thanks for the code example, works perfect! I am not a PHP coder myself and have one additional question that perhaps you or somebody else might be able to answer;

    I need to generate a similar affiliate URL that contains multiple fields after the “?”. Something like: http://astore.amazon.com/affiliateID?azdp=0123456789&a=1111&b=2222

    My question is what the php code would be to also GET the “a=” and “b=” into the URL? I am not sure what the correct syntax for that would be in PHP.

    I have to define these different parts of the URL in here I guess;

    if (isset($_GET['slp'])) {
    $dp = $_GET['slp'];

    Many thanks!

  • Eric,
    I missed seeing the e-mail notice for your comment, sorry. Yes, you can use the same method to GET additional args from the querystring and then echo them into the iframe tag. As long as the aStore expects your variables and knows what to do with them, it should work.

    If your WP Page always expects the same aStore variables you could simply echo the args right into the iframe tag’s src:

    http://astore.amazon.com/affiliateID?<?php echo $_GET['varname'] . '&#038;' . $_GET['a'] . '&#038;' . $_GET['b']; ?>

    The echo statement writes out the values of ‘varname’, ‘a’, and ‘b’ with an ampersand in between each argument.

Leave a Reply

  

  

  


*

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>