Developer Documentation

Integrate the TrendSync plugin across modern web stacks.

This guide is based on the current project implementation: the official loader script, the API-key metadata endpoint, the indexing webhook, and the WordPress plugin settings already shipped in this codebase.

SPA

React

Browser loader for SPAs and client-heavy React applications.

Universal

JavaScript Websites

Fastest drop-in option for plain HTML sites and static pages.

SSR

PHP

Server-rendered metadata for custom PHP sites and frameworks.

Official Plugin

WordPress

Official plugin with settings, verification, caching, and status reporting.

App Router

Next.js

Use either the loader script or fetch metadata in the App Router.

How TrendSync Works

Every connector in this project follows the same runtime contract, so once the credentials are ready you can plug it into almost any stack.

1

TrendSync stores the selected metadata recommendation for a client.

2

Your site calls `GET /api/plugin/metadata` with the `X-Api-Key` header.

3

The response includes title, description, keywords, Open Graph, Twitter Card, structured data, and canonical URL.

4

After successful injection, the connector can notify TrendSync with `POST /api/indexing/metadata-injected`.

Before You Start

An active TrendSync account with a registered website and selected metadata option.
Your generated API key from the TrendSync dashboard.
The TrendSync backend base URL, for example `https://api.yourdomain.com`.
A site where you can edit the document `<head>` or inject server-rendered metadata.
The easiest place to collect these values is the dashboard integration flow at ` /dashboard/connectors ` and the API key screen at ` /dashboard/settings `.
Browser-based integrations use the API key as a public integration credential. Treat it as scoped connector access, not as a private server secret.

Official Loader Script

Use this when you want the browser to fetch metadata and inject it automatically. This is the same contract exposed by `backend/controller/pluginController.js`.

<!-- Place this inside <head> -->
<script
  async
  src="https://api.yourdomain.com/api/plugin/trendsync.min.js"
  data-api-key="YOUR_API_KEY"
  data-auto-inject="true"
></script>

Current live endpoint contract: `GET /api/plugin/metadata` with `X-Api-Key`, followed by optional `POST /api/indexing/metadata-injected`.

Optional Injection Reporting

After metadata is applied, your connector can notify TrendSync so automatic indexing workflows can continue.

await fetch("https://api.yourdomain.com/api/indexing/metadata-injected", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Api-Key": "YOUR_API_KEY",
  },
  body: JSON.stringify({
    url: window.location.href,
    metadataType: "full",
  }),
});

Legacy Connector Flow

TrendSync still ships an older compatibility path in the backend. New integrations should use `trendsync.min.js` plus `X-Api-Key`, but existing installs may still rely on the legacy client-ID flow.

1

`GET /api/plugin/loader.js` returns the older browser loader.

2

That loader expects a `key` query param for `clientId` and an optional `token` query param.

3

It fetches `GET /api/plugin/seo-data/:clientId?path=...` instead of `/api/plugin/metadata`.

4

It is still present in the backend for backward compatibility, but the API-key based `trendsync.min.js` flow is the preferred integration path.

<!-- Legacy loader -->
<script
  src="https://api.yourdomain.com/api/plugin/loader.js?key=CLIENT_ID&token=OPTIONAL_BEARER_TOKEN"
  async
></script>
Legacy route summary: `GET /api/plugin/loader.js` `GET /api/plugin/seo-data/:clientId?path=/current-path` Use this only when maintaining older integrations that were built before the API-key based connector.

React Applications

Best for single-page apps, Vite projects, and client-side React sites where the browser can inject SEO tags after hydration.

1. Generate or copy your API key from TrendSync.
2. Add `REACT_APP_TRENDSYNC_API_KEY` to your environment file.
3. Mount the loader once near the root of the app, for example in `App.tsx`.
4. Verify that the request to `/api/plugin/metadata` succeeds and the document <head> updates.
5. If the backend returns `403`, confirm the client still has an active plan or trial.
React SPA note: because tags are injected in the browser, use this mode when client-side SEO is acceptable for your deployment.
import { useEffect } from "react";

export function TrendSyncLoader() {
  useEffect(() => {
    const script = document.createElement("script");
    script.src = "https://api.yourdomain.com/api/plugin/trendsync.min.js";
    script.async = true;
    script.dataset.apiKey = process.env.REACT_APP_TRENDSYNC_API_KEY || "";
    script.dataset.autoInject = "true";
    document.head.appendChild(script);

    return () => {
      document.head.removeChild(script);
    };
  }, []);

  return null;
}
// App.tsx
import { TrendSyncLoader } from "./TrendSyncLoader";

export default function App() {
  return (
    <>
      <TrendSyncLoader />
      {/* your routes */}
    </>
  );
}

JavaScript-Based Websites

Best for plain HTML, marketing sites, static exports, legacy websites, or any site where you can edit the global document head.

Setup Steps

1. Open the shared layout or the page template that controls <head>.
2. Paste the loader script before the closing </head> tag.
3. Keep `data-auto-inject="true"` unless you plan to fetch metadata manually.
4. Publish, then inspect the page source and browser devtools to confirm the tags appear.
5. Expect `401` for missing API keys, `404` for invalid keys, and `403` when the subscription is inactive.

Snippet

<!-- Place this inside <head> -->
<script
  async
  src="https://api.yourdomain.com/api/plugin/trendsync.min.js"
  data-api-key="YOUR_API_KEY"
  data-auto-inject="true"
></script>

PHP-Based Websites

Best for Laravel, Symfony, CodeIgniter, custom PHP sites, or any server-rendered application where metadata should be produced before HTML reaches the browser.

1. Store the backend URL and API key in server-side config, not public templates.
2. Fetch `GET /api/plugin/metadata` during the request lifecycle.
3. Render title, description, keywords, canonical, Open Graph, and JSON-LD in your head partial.
4. Add caching at the application or reverse-proxy layer to reduce repeated API calls.
Server-side integrations are the best fit when you want to keep the API key out of the browser.
<?php
$backendUrl = 'https://api.yourdomain.com';
$apiKey = 'YOUR_API_KEY';

function fetchTrendSyncMetadata(string $backendUrl, string $apiKey): ?array {
    $ch = curl_init($backendUrl . '/api/plugin/metadata');
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Accept: application/json',
            'X-Api-Key: ' . $apiKey,
        ],
        CURLOPT_TIMEOUT => 10,
    ]);

    $response = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($status < 200 || $status >= 300 || !$response) {
        return null;
    }

    return json_decode($response, true);
}

$data = fetchTrendSyncMetadata($backendUrl, $apiKey);
$meta = $data['metadata'] ?? null;
?>

<?php if ($meta): ?>
  <title><?= htmlspecialchars($meta['title'] ?? '') ?></title>
  <meta name="description" content="<?= htmlspecialchars($meta['description'] ?? '') ?>">
  <meta name="keywords" content="<?= htmlspecialchars(implode(', ', $meta['keywords'] ?? [])) ?>">
  <link rel="canonical" href="<?= htmlspecialchars($meta['canonical'] ?? '') ?>">
<?php endif; ?>

WordPress

This project already ships an official WordPress plugin that adds an admin settings page, verifies the connection, caches metadata for each path, injects SEO tags in `wp_head`, and reports plugin status back to TrendSync.

1. Upload the plugin from `connectors/wordpress/kridinifytech-seo-connector-for-trendsync/` or install the packaged zip.
2. In WordPress admin, open Settings → TrendSync.
3. Fill in `API Key`, `Client ID`, `Backend URL`, and `Website URL`.
4. Leave `Auto Inject` enabled unless you want to disable metadata injection temporarily.
5. Save settings, then click Verify Connection.
WordPress plugin settings

api_key      -> TrendSync API key
client_id    -> Stored by the plugin UI, but current metadata fetch uses the API key
backend_url  -> https://api.yourdomain.com
website_url  -> https://your-wordpress-site.com
auto_inject  -> enabled by default
Runtime behavior from the plugin code: fetch metadata with retries, cache per-path responses for 10 minutes, inject tags in `wp_head`, override the document title when metadata exists, and report failures or success to `/api/plugin/status`.

Next.js Applications

Next.js supports two good integration styles: use the official browser loader for fast setup, or fetch metadata server-side inside the App Router for stronger SSR control.

Option A: Loader Script

Use this when you want the same behavior as a normal JavaScript integration.

import Script from "next/script";

export function TrendSyncScript() {
  return (
    <Script
      id="trendsync-loader"
      src="https://api.yourdomain.com/api/plugin/trendsync.min.js"
      strategy="afterInteractive"
      data-api-key={process.env.NEXT_PUBLIC_TRENDSYNC_API_KEY}
      data-auto-inject="true"
    />
  );
}

Option B: Server Metadata

Use this when you want metadata resolved during rendering with App Router APIs.

const BACKEND_URL = process.env.TRENDSYNC_BACKEND_URL!;
const API_KEY = process.env.TRENDSYNC_API_KEY!;

async function getTrendSyncMetadata() {
  const response = await fetch(`${BACKEND_URL}/api/plugin/metadata`, {
    headers: {
      "X-Api-Key": API_KEY,
      Accept: "application/json",
    },
    next: { revalidate: 600 },
  });

  if (!response.ok) {
    return null;
  }

  return response.json();
}

export async function generateMetadata() {
  const data = await getTrendSyncMetadata();
  const metadata = data?.metadata;

  if (!metadata) {
    return {};
  }

  return {
    title: metadata.title,
    description: metadata.description,
    keywords: metadata.keywords,
    openGraph: metadata.openGraph,
    twitter: metadata.twitterCard,
    alternates: {
      canonical: metadata.canonical,
    },
  };
}
Recommended for production SEO: prefer server-side metadata generation when your deployment needs search engines to see tags immediately in the rendered HTML and you want the API key to stay server-side.

Configuration Checklist

Metadata option selected inside TrendSync.
Valid API key copied into the target application.
Backend URL points to the live TrendSync backend.
Client-side or server-side caching strategy chosen.
Browser integrations use the public connector endpoints with `X-Api-Key` allowed by CORS.
Injection verified in browser devtools or rendered HTML output.

Troubleshooting

`401` or `404`: check the `X-Api-Key` value and make sure the account still has active access.
`403`: confirm the client has an active plan or trial. Connector endpoints are subscription-gated.
No metadata returned: confirm a metadata option has been generated and selected in the dashboard.
WordPress not updating: save settings again, verify the backend URL, and clear any page cache.
Duplicate tags: choose either automatic browser injection or custom manual injection for the same tag set, not both.