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

Frequently asked questions

How do I add Similar AI internal links to my site using a plain JavaScript snippet?

You can integrate Similar AI by placing a client-side script tag in your page template, which automatically queries the Similar AI Linking Agent and injects relevant internal links into designated HTML elements. No server-side changes are required - just add the snippet once and all matching pages update dynamically.

Can I deploy the Similar AI script through Google Tag Manager without touching my site code?

Yes, the Similar AI JavaScript snippet can be added as a Custom HTML tag inside Google Tag Manager, triggered on the page views where you want internal links to appear. This means your development team doesn't need to be involved for initial setup or future configuration changes.

Which HTML elements does the Similar AI script target for link injection?

You designate target elements by adding a specific data attribute or CSS class to the containers where you want internal links rendered, such as product descriptions or category introductions. The script then scans those elements and inserts contextually relevant links identified by the Linking Agent.

Will the client-side JavaScript integration affect my page load performance?

The snippet is designed to load asynchronously so it does not block your page's critical rendering path. Link injection happens after the main content is interactive, keeping Core Web Vitals scores unaffected by the integration.

Does the GTM integration work alongside Similar AI's other agents like the Content Agent or New Pages Agent?

Yes, the JavaScript and GTM integration is a delivery layer that surfaces links generated by the Linking Agent, which itself draws on the full Similar AI platform including signals from the Content Agent and New Pages Agent. Any new pages or content updates made by those agents are automatically reflected in the links the script injects, without requiring you to update your GTM configuration.

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.