As a self-published author selling books through Amazon KDP, one of the most frustrating challenges I faced was creating links that would work for readers around the world. If you’re a KDP author, you probably know the problem all too well: Amazon gives you separate links for each country store (amazon.com, amazon.co.uk, amazon.ca, etc.), but there’s no easy way to create a single “smart link” that automatically sends readers to their local Amazon store.
This creates a dilemma: Do you clutter your website with a dozen different links for different countries? Or do you just link to amazon.com and potentially lose international sales when readers are sent to the wrong store and get confused?
Fortunately, I’ve found a simple solution that doesn’t require expensive third-party services or complicated setup. In this post, I’ll show you how to create smart Amazon links that automatically detect your reader’s location and redirect them to the appropriate Amazon store.
See it in action here: https://adventuresofmax.uk/showcase
The Problem with Standard Amazon Links
When you publish a book through KDP, Amazon assigns it a unique identifier called an ASIN (Amazon Standard Identification Number). Your book has the same ASIN across all Amazon stores, but the domain changes depending on the country:
- US: amazon.com
- UK: amazon.co.uk
- Canada: amazon.ca
- Germany: amazon.de
- And so on…
Amazon doesn’t provide an official way to create a universal link that works for all countries. Their “OneLink” service is primarily for Amazon Associates (affiliate marketers) and requires setting up Associates accounts in multiple countries.
The Solution: Location-Based Smart Links
My solution uses a bit of JavaScript to:
- Detect the reader’s country using a free geolocation API
- Redirect them to the appropriate Amazon store for that country
- Keep the book’s ASIN in the URL so they land on the correct book page
The best part is that this all happens automatically, with just a single line of HTML for each book!
How It Works
When a reader clicks on your “Buy Now” button:
- The script prevents the default link behavior
- It calls the ipapi.co API to determine the reader’s country
- It maps the country code to the corresponding Amazon domain
- It redirects the reader to the correct Amazon store with your book’s ASIN
For example, if a reader in Germany clicks your link, they’ll be taken to amazon.de. If a reader in Australia clicks the same link, they’ll go to amazon.com.au.
How to Implement It on Your WordPress Site
Here’s how I set it up on my WordPress site with Elementor:
Step 1: Create a JavaScript File
First, I created a file called amazon-redirect.js with this code:
javascriptCopydocument.addEventListener('click', function(event) {
const button = event.target.closest('.amazon-redirect-button');
if (button) {
event.preventDefault();
const asin = button.getAttribute('data-asin');
fetch('https://ipapi.co/json/')
.then(response => response.json())
.then(data => {
const countryCode = data.country_code;
const amazonDomains = {
'US': 'com',
'GB': 'co.uk',
'UK': 'co.uk',
'CA': 'ca',
'DE': 'de',
'FR': 'fr',
'IT': 'it',
'ES': 'es',
'JP': 'co.jp',
'BR': 'com.br',
'IN': 'in',
'MX': 'com.mx',
'AU': 'com.au',
'NL': 'nl',
'SG': 'sg',
'AE': 'ae'
};
const domain = amazonDomains[countryCode] || 'com';
window.location.href = `https://www.amazon.${domain}/dp/${asin}`;
})
.catch(() => {
window.location.href = `https://www.amazon.com/dp/${asin}`;
});
}
});Step 2: Register the Script
In my theme’s functions.php file, I added:
phpCopyfunction enqueue_amazon_script() {
wp_enqueue_script('amazon-redirect', get_template_directory_uri() . '/amazon-redirect.js', array(), '1.0', true);
}
add_action('wp_enqueue_scripts', 'enqueue_amazon_script');Step 3: Create Smart “Buy Now” Buttons
In Elementor, I added HTML widgets with this code for each book:
htmlCopy<div style="text-align: center;">
<a href="#" class="amazon-redirect-button elementor-button elementor-size-sm" data-asin="B0DZSPVYFB">
<span class="elementor-button-content-wrapper">
<span class="elementor-button-text">Buy Now</span>
</span>
</a>
</div>I simply change the data-asin attribute for each different book.
Step 4: Style the Buttons
I added some CSS to make the buttons match my site’s design:
cssCopy.amazon-redirect-button {
display: block;
width: fit-content;
margin: 0 auto;
padding: 12px 24px;
background-color: #61ce70;
color: white;
text-decoration: none;
border-radius: 3px;
font-family: "Roboto", Sans-serif;
font-size: 15px;
font-weight: 500;
text-transform: none;
transition: all 0.3s;
}
.amazon-redirect-button:hover {
background-color: #23a455;
color: white;
}Benefits of This Approach
- Better user experience: Readers are automatically taken to the Amazon store they can actually buy from.
- Higher conversion rates: No more lost sales due to region restrictions.
- Cleaner design: No need for multiple links or country flags cluttering your website.
- No ongoing costs: This solution is completely free, with no subscription fees.
- Full control: You own the code and can modify it as needed.
Technical Notes
- The geolocation API (ipapi.co) has a free tier that should work fine for most author websites.
- The script falls back to amazon.com if it can’t detect the reader’s location.
- This approach doesn’t track affiliate commissions across different countries (for that, you’d need Amazon OneLink or a paid service).
Conclusion
With just a few lines of code, you can create smart Amazon links that provide a seamless experience for your readers around the world. No more frustrating “this title isn’t available in your region” messages, and no more cluttered pages with multiple country-specific links.
Have you tried something similar on your author website? Let me know in the comments if you have any questions or suggestions for improving this approach!