Skip to main content
Linking Agent

JavaScript and Google Tag Manager Internal Linking Integration

Add Similar AI internal links to any website using a client-side JavaScript snippet or Google Tag Manager. No server-side changes required.

Robin AllensonBy Robin Allenson, CEO & Co-Founder

Client-side integration overview

In addition to the server-side integration, the Similar AI Linking Agent API also works with a client-side integration. You can add a script block manually or use Google Tag Manager (GTM), then place an empty HTML element in your template (for example, in the footer). The script pulls links using the API key we provide and updates the page automatically.

This approach works well for sites where you cannot modify server-side rendering, including static site generators, hosted platforms, and CMS tools like Ghost.

Option 1: Direct JavaScript snippet

The simplest approach is to add a script tag and an empty HTML element directly to your page template. The script loads asynchronously and populates the element with internal links returned by the Linking Agent API.

Step 1: Add the script tag

Place this script tag in your HTML. Replace XXX with the API key we provide. Contact us if you do not have one yet.

<script
  src="https://isentropic-snow-282609.ew.r.appspot.com/api/js-internal-linking/?apikey=XXX"
  defer
></script>

Step 2: Add the HTML element

Place this empty element where you want the internal links to appear - typically in the footer or sidebar of your template.

<div id="similarai-relatedSearches" class="nav"></div>

Once both are in place, the script will fetch links from the Linking Agent API on each page load and render them inside the element. No further configuration is needed.

Option 2: Google Tag Manager

If you manage scripts through GTM, you can add the Linking Agent integration as a custom HTML tag. This gives you control over which pages load the script and when.

Step 1: Create a new tag

Go to your GTM workspace, navigate to Tags, and create a new Custom HTML tag with the following content. Replace XXX with your API key.

<script>
  var script = document.createElement('script');
  script.defer = true;
  script.src = "https://isentropic-snow-282609.ew.r.appspot.com/api/js-internal-linking/?apikey=XXX";
  document.getElementsByTagName('head')[0].appendChild(script);
</script>

Step 2: Add a trigger

Create a trigger for the tag. For example, use a Page View trigger filtered to the pages that should pull internal links from Similar AI. You can target all pages or use a URL path condition to limit it to specific sections of your site.

Step 3: Add the HTML element

Just like the direct approach, you still need the empty container element in your HTML template:

<div id="similarai-relatedSearches" class="nav"></div>

Step 4: Preview and publish

Use GTM Preview mode to verify the tag fires correctly on your target pages. Once confirmed, publish the container.

Related guides

Ready to add internal links to your site?

Get started with the Linking Agent in minutes. We will provide your API key and help you configure the integration.