Login to explore other opportunities.

AI Search Engine Optimization & Schema Markup Instructions

SEO Page Setup

Follow the steps below to set up your page after generating the API key:

Step 1: Add the Token Key to Your HTML Page

Once you have your unique API Key, you'll need to include it in your webpage so it can fetch SEO data dynamically. Here’s how:

  1. Open your HTML file (the page where you want to implement the SEO data).
  2. Add the following meta tag inside the <head> section of your HTML:
  3. <meta name="token-key" content="YOUR_API_KEY_HERE">
  4. Replace YOUR_API_KEY_HERE with the API Key you generated.

Step 2: Add the JavaScript to Fetch SEO Data

Next, add the JavaScript code that will fetch the SEO data based on the token key and update the page dynamically:

  1. Copy and paste the following JavaScript code into the <head> section of your HTML:
  2. 
    <script>
        // Fetch SEO Data from the API
        const tokenKey = document.querySelector('meta[name="token-key"]').getAttribute('content');
    
        if (!tokenKey) {
            console.error("Token key not found in the meta tag.");
        } else {
            fetch('https://www.jaysoftware.co.uk/af/a_seo_ai/api/get-seo-code/', {
                method: 'POST', // Ensure POST method is used
                headers: {
                    'Content-Type': 'application/json' // Content type for JSON
                },
                body: JSON.stringify({ token: tokenKey }) // Send the token in the request body
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                return response.json();
            })
            .then(data => {
                if (data.error) {
                    console.error("Error fetching SEO data:", data.error);
                    return;
                }
    
                if (data.title) {
                    document.title = data.title;
                }
    
                if (data.description) {
                    let metaDescription = document.querySelector('meta[name="description"]');
                    if (!metaDescription) {
                        metaDescription = document.createElement('meta');
                        metaDescription.name = 'description';
                        document.head.appendChild(metaDescription);
                    }
                    metaDescription.setAttribute('content', data.description);
                }
    
                if (data.keywords) {
                    let metaKeywords = document.querySelector('meta[name="keywords"]');
                    if (!metaKeywords) {
                        metaKeywords = document.createElement('meta');
                        metaKeywords.name = 'keywords';
                        document.head.appendChild(metaKeywords);
                    }
                    metaKeywords.setAttribute('content', data.keywords);
                }
    
                if (data.canonical_url) {
                    let canonicalLink = document.querySelector('link[rel="canonical"]');
                    if (!canonicalLink) {
                        canonicalLink = document.createElement('link');
                        canonicalLink.rel = 'canonical';
                        document.head.appendChild(canonicalLink);
                    }
                    canonicalLink.href = data.canonical_url;
                }
    
                if (data.schema_markup) {
                    let schemaScript = document.createElement('script');
                    schemaScript.type = 'application/ld+json';
                    schemaScript.textContent = data.schema_markup;
                    document.head.appendChild(schemaScript);
                }
            })
            .catch(error => console.error("Fetch error:", error));
        }
    </script>
            

Step 3: Customize Your Page Content

The SEO data will automatically update the following elements in your webpage:

Step 4: Save and Test Your Page

  1. Save your changes to the HTML file.
  2. Open your page in a browser.
  3. Check the page source to confirm that the SEO metadata is correctly added. Look for <meta> tags for description, keywords, and the <link> tag for the canonical URL. You should also see a <script> tag for schema markup.

Step 5: Monitor and Troubleshoot

If you encounter any issues:

Example Setup


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SEO Page Setup</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="token-key" content="YOUR_API_KEY_HERE">

    <script>
        // Add the JavaScript for fetching SEO data here...
    </script>
</head>
<body>
    <h1>Welcome to Your SEO Optimized Page!</h1>
    <p>This page’s SEO data is dynamically loaded based on your API Key.</p>
</body>
</html>