How to dynamically show related Amazon products
If you are using Amazon Associates Program to earn money you need to show Amazon products with your affiliate link on your website. For many blogs it is a good idea to display related Amazon products below the posts. While Amazon will try to show related products it is much better to initially show products with the default search phrase that are directly related the post content. There is a simple way to insert one block with code for Amazon Native Shopping Ads that will always show products based on post tags.
Amazon has discontinued Native Shopping ads, showing the code only as an example
Sign in to Amazon Associates, go to Widgets/Widget Source, choose ad type and set parameters. For titles and search terms use Ad Inserter data shortcode. For example, the code below would display amazon products related to post tags (showing code for normal and AMP pages – you can use only normal code above the AMP separator if you are not using AMP plugin):
<script type="text/javascript">
amzn_assoc_placement = "adunit0"; amzn_assoc_search_bar = "true"; amzn_assoc_tracking_id = "ad-inserter-20"; amzn_assoc_search_bar_position = "top"; amzn_assoc_ad_mode = "search"; amzn_assoc_ad_type = "smart"; amzn_assoc_marketplace = "amazon"; amzn_assoc_region = "US"; amzn_assoc_title = "Search Results from Amazon"; amzn_assoc_default_search_phrase = "[adinserter data='smart-tag']"; amzn_assoc_default_category = "All"; amzn_assoc_linkid = "cf1873f027a57f63cede634cfd444bea";
</script> <script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script> [ADINSERTER AMP] <amp-ad height = "200" type = "a9" data-amzn_assoc_placement = "adunit0" data-amzn_assoc_search_bar = "true" data-amzn_assoc_tracking_id = "ad-inserter-20" data-amzn_assoc_search_bar_position = "top" data-amzn_assoc_ad_mode = "search" data-amzn_assoc_ad_type = "smart" data-amzn_assoc_marketplace = "amazon" data-amzn_assoc_region = "US" data-amzn_assoc_title = "Search Results from Amazon" data-amzn_assoc_default_search_phrase = "[adinserter data='smart-tag']" data-amzn_assoc_default_category = "All" data-amzn_assoc_linkid = "cf1873f027a57f63cede634cfd444bea"> </amp-ad>
Use your own tracking id!
Please note [adinserter data='smart-tag']
as the default search phrase. This makes this widget contextual. It will show products related to the WordPress tags for this post (make sure you set them). You can also try with [adinserter data='tag']
, [adinserter data='short-title']
, [adinserter data='category']
or [adinserter data='short-category']
. For detailed description check options for data shortcodes.
Check also documentation on Amazon AMP ad codes. Most of the AMP attributes are coming from the normal Amazon Javascript ad code – they have a data-
prefix in front of them. So amzn_assoc_ad_type
becomes data-amzn_assoc_ad_type
. Check this example for Amazon Native Shopping Ads.
The A9 amp ad unit supports the Search, Recommendation and Custom ad widgets of the Native Shopping Ads program. These widgets would need to be created first.
Manually specifying default search phrase with shortcode parameters
Another approach to show related products is to insert the block with a shortcode and manually specify the default search phrase. Configure one block with this code (in this example we are using block 1):
<script type="text/javascript">
amzn_assoc_placement = "adunit0"; amzn_assoc_search_bar = "true"; amzn_assoc_tracking_id = "ad-inserter-20"; amzn_assoc_search_bar_position = "top"; amzn_assoc_ad_mode = "search"; amzn_assoc_ad_type = "smart"; amzn_assoc_marketplace = "amazon"; amzn_assoc_region = "US"; amzn_assoc_title = "Search Results from Amazon"; amzn_assoc_default_search_phrase = "{#search:#}"; amzn_assoc_default_category = "All"; amzn_assoc_linkid = "cf1873f027a57f63cede634cfd444bea";
</script> <script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>
Use your own tracking id!
Please note {#search:#}
as the default search phrase. This tag will be replaced with the search
parameter (attribute) from the shortcode (you can use any attribute name). For example, to show products related to WordPress plugin development using block 1 use this shortcode:
[adinserter block="1" search="WordPress plugin development"]
For detailed description check shortcode attributes.