I used ChatGPT to build a tool that automatically turns certain keywords into hyperlinks with my affiliate links.
One thing we do here at AI Growth Guys is affiliate marketing. That means we put our affiliate link to certain products into our articles.
I love writing articles, but I hate wasting time doing this kind of linking.
If I do this manually, I need to:
- Look up my affiliate links
- Look up any keywords in my article I want to link
- Cut and paste the correct affiliate link into each keyword
This process takes quite a bit of time.
I wanted to get a program to do this for me.
Iâm not a programmer. I noticed there are some programs that do this, but a lot of them cost $49 bucks a month, which I donât want to pay.
So I wanted to see if ChatGPT could do this for me.
Google Apps Script Video – AI Affiliate Link Tool
Let me first explain what I do and what exactly I needed done.
I write my first draft of every article (including this article) in Google Docs. I find it the easiest place to write in. Then Addison, my business partner here at AI Growth Guys, cuts and pastes my article into our WordPress editor and does the rest of the formatting and editing.
I wanted this automatic linking software to work directly with Google Docs.
I asked ChatGPT how to do this, and they recommended I use a âGoogle Apps Scriptâ.
Iâd never heard of that, but itâs pretty cool. This âapps scriptâ also works with other Google products like Google Sheets.
To do this, from inside a new Google Doc, you need to click on:
Extensions > Apps Script
This will open up a new window. This window corresponds with this particular Google Doc that you are working on.
It looks like this:
I then explained to chatGPT what I wanted to do.
- I uploaded all of my affiliate links to ChatGPT with the corresponding keywords I wanted to link from.
(For example: My affiliate link to Beehiiv is: https://www.beehiiv.com?via=andrew-best
I would say, âBeehiiv: https://www.beehiiv.com?via=andrew-bestâ)
So every time I write the word âBeehiivâ, I want it linked like this Beehiiv
- I did that for each of my affiliate links. I told ChatGPT that everytime I the word âBeehiivâ shows up in my article, I want it hyperlinked with my affiliate linkâ
- I did this with all of my affiliate links.
- I said to ChatGPT. âMake me a Google apps script that does this automaticallyâ. I also asked, âWhat is the best way to do this?â
ChatGPT gave the great idea to first make a new menu tab called, âMy Custom Scriptsâ
It looks like this.
A standard Google Doc doesnât have this âMy Custom Scriptsâ menu option.
I didnât know that you could make your own!
Anyway, I asked ChatGPT to first make me that menu bar.
It gave this code:
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('My Custom Scripts')
.addItem('Insert Affiliate Links', 'insertAffiliateLinks')
.addToUi();
}
In order to implement this, you need to go into your Apps Script, like I showed above by clicking on:
Extensions > Apps Script
Then you delete everything that is in there, which is this:
function myFunction() {
}
So just delete that, and then cut and paste the above code into its place and click âsaveâ.
Then click ârunâ.
You will see a couple of pop up windows that ask for permissions. These are really simple.
Just make sure that you are logged in, and click âyesâ to allow the permissions they are asking.
At this point, you will have your new menu option called âCustom Apps Scriptâ.
Then I asked ChatGPT to make the rest of the apps script that would automatically hyperlink each of my chosen keywords with the corresponding affiliate link.
Here was the exact script it made for me:
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('My Custom Scripts')
.addItem('Insert Affiliate Links', 'insertAffiliateLinks')
.addToUi();
}
function insertAffiliateLinks() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
// Define your keywords and corresponding affiliate links
var links = {
'11 Labs': 'https://elevenlabs.io/?from=partnermeyer5644',
'HeyGen': 'https://heygen.com/?sid=rewardful&via=andrew-best',
'Mangools': 'https://mangools.com#a57df4ec7285f734f44889a97',
'TubeBuddy': 'https://www.tubebuddy.com/pricing?a=andrewbest',
'Skool': 'https://www.skool.com/refer?ref=97d294e27b5b4519847e464d4c6eb947',
'Beehiiv': 'https://www.beehiiv.com?via=andrew-best',
'Stammer.ai': 'https://stammer.ai/?via=andrew',
'Exploding Topics': 'https://explodingtopics.com/?via=andrew-best',
'Apollo': 'https://apollo.partnerlinks.io/6upajoxr847f',
'Riverside': 'https://www.riverside.fm?via=andrew-best',
'Repurpose.io': 'https://repurpose.io/?aff=256322',
'vidIQ.com': 'https://vidiq.com/aigrowthguys',
'ConvertKit': 'https://convertkit.com/?lmref=DSxnZA',
'Go High Level': 'https://www.gohighlevel.com/?fp_ref=hcbyk',
'Partnerstack': 'https://buy.partnerstackprm.com/927y2duoum3i',
'CreativeFuel.ai': 'https://creativefuel.ai?via=andrew',
'Rewardful': 'https://www.getrewardful.com/?via=andrew-best',
'Tapfiliate': 'https://tapfiliate.com/?ref=mjk2ndr'
};
// Iterate over each word-URL pair
Object.keys(links).forEach(function(word) {
var url = links[word];
var foundElement = body.findText(word);
while (foundElement != null) {
var foundText = foundElement.getElement().asText();
// Get the start and end indices of the word
var startOffset = foundElement.getStartOffset();
var endOffset = foundElement.getEndOffsetInclusive();
// Set the link URL for the word
foundText.setLinkUrl(startOffset, endOffset, url);
// Find the next occurrence of the word
foundElement = body.findText(word, foundElement);
}
});
}
Basically, if you cut and paste this exact code into the apps script part I showed above, this will work for you.
Note: Obviously, youâd need to make it with your own affiliate links, but thatâs the only thing youâd need to change.
Iâll give you 2 screenshots to show you how this works.
Let me first write 2 sentences. (This will work for a long article, Iâm just showing you what it looks like).
I want the following keywords hyperlinked:
- Beehiiv
- ConvertKit
- Exploding Topics
Here is how my 2 sentence article looks before I run the script.
You can see that nothing is linked yet.
I moused over âMy Custom Scriptsâ so you can see the âInsert Affiliate Linksâ show up in the dropdown menu
I then click on âInsert Affiliate Linksâ
And thatâs it!!
Here is what it looks like. Iâve moused over the word âBeehiivâ just to show you that all of these words are actually hyperlinked, and just highlighted in blue.
Now, everytime I write an article, I use this same Apps Script, and then I write the article. When Iâm finished, I click ârunâ to get all of my links in there.
Iâd say this saves me about 15 minutes per article, because I donât need to find all of my links, and then manually start putting them in.
Another benefit of this time saving thing is that this tool never makes a mistake.
With this extra time, I can immediately start working on my next article and earn more money because of my increased productivity.
Some of the links in this post may be affiliate links. We might earn a small commission at no extra cost to you. Itâs one way to support us and keep things running. We also only put affiliate links we believe in fyi.