diff --git a/integrations/wistia/assets/icon.svg b/integrations/wistia/assets/icon.svg
new file mode 100644
index 000000000..1c0db6fbd
--- /dev/null
+++ b/integrations/wistia/assets/icon.svg
@@ -0,0 +1,4 @@
+
\ No newline at end of file
diff --git a/integrations/wistia/assets/wistia-preview.jpg b/integrations/wistia/assets/wistia-preview.jpg
new file mode 100644
index 000000000..10eaa3003
Binary files /dev/null and b/integrations/wistia/assets/wistia-preview.jpg differ
diff --git a/integrations/wistia/gitbook-manifest.yaml b/integrations/wistia/gitbook-manifest.yaml
new file mode 100644
index 000000000..6dd4bba8a
--- /dev/null
+++ b/integrations/wistia/gitbook-manifest.yaml
@@ -0,0 +1,25 @@
+name: wistia
+title: Wistia
+icon: ./assets/icon.svg
+previewImages:
+ - ./assets/wistia-preview.png
+description: Add Wistia video analytics to your GitBook site.
+visibility: public
+script: ./src/index.ts
+scopes:
+ - site:script:inject
+ - site:script:cookies
+organization: gitbook
+contentSecurityPolicy:
+ script-src: https://fast.wistia.com;
+summary: |
+ # Overview
+ This integration adds the Wistia analytics script to your published GitBook site.
+
+ # How it works
+ The integration injects the Wistia script (https://fast.wistia.com/assets/external/E-v1.js)
+ on your page to enable video analytics tracking.
+
+categories:
+ - analytics
+target: site
\ No newline at end of file
diff --git a/integrations/wistia/package.json b/integrations/wistia/package.json
new file mode 100644
index 000000000..63a2e3085
--- /dev/null
+++ b/integrations/wistia/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "@gitbook/integration-wistia",
+ "version": "1.0.0",
+ "private": true,
+ "dependencies": {
+ "@gitbook/api": "*",
+ "@gitbook/runtime": "*"
+ },
+ "devDependencies": {
+ "@gitbook/cli": "workspace:*",
+ "@gitbook/tsconfig": "workspace:*"
+ },
+ "scripts": {
+ "typecheck": "tsc --noEmit",
+ "publish-integrations-staging": "gitbook publish .",
+ "check": "gitbook check",
+ "publish-integrations": "gitbook publish ."
+ }
+}
\ No newline at end of file
diff --git a/integrations/wistia/src/index.ts b/integrations/wistia/src/index.ts
new file mode 100644
index 000000000..eabb7954d
--- /dev/null
+++ b/integrations/wistia/src/index.ts
@@ -0,0 +1,23 @@
+import {
+ createIntegration,
+ FetchPublishScriptEventCallback,
+ RuntimeContext,
+ RuntimeEnvironment,
+} from '@gitbook/runtime';
+
+import script from './script.raw.js';
+
+type WistiaRuntimeContext = RuntimeContext>;
+
+export const handleFetchEvent: FetchPublishScriptEventCallback = async () => {
+ return new Response(script as string, {
+ headers: {
+ 'Content-Type': 'application/javascript',
+ 'Cache-Control': 'max-age=604800',
+ },
+ });
+};
+
+export default createIntegration({
+ fetch_published_script: handleFetchEvent,
+});
\ No newline at end of file
diff --git a/integrations/wistia/src/script.raw.js b/integrations/wistia/src/script.raw.js
new file mode 100644
index 000000000..84c87ca9c
--- /dev/null
+++ b/integrations/wistia/src/script.raw.js
@@ -0,0 +1,24 @@
+const GRANTED_COOKIE = '__gitbook_cookie_granted';
+
+function getCookie(cname) {
+ const name = `${cname}=`;
+ const decodedCookie = decodeURIComponent(document.cookie);
+ const ca = decodedCookie.split(';');
+ for (let i = 0; i < ca.length; i++) {
+ let c = ca[i];
+ while (c.charAt(0) === ' ') {
+ c = c.substring(1);
+ }
+ if (c.indexOf(name) === 0) {
+ return c.substring(name.length, c.length);
+ }
+ }
+ return '';
+}
+
+if (getCookie(GRANTED_COOKIE) === 'yes') {
+ const script = document.createElement('script');
+ script.src = 'https://fast.wistia.com/assets/external/E-v1.js';
+ script.async = true;
+ document.head.appendChild(script);
+}
\ No newline at end of file
diff --git a/integrations/wistia/tsconfig.json b/integrations/wistia/tsconfig.json
new file mode 100644
index 000000000..7e359bb57
--- /dev/null
+++ b/integrations/wistia/tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "extends": "@gitbook/tsconfig/base.json",
+ "compilerOptions": {
+ "outDir": "./dist"
+ },
+ "include": ["src/**/*"]
+}
\ No newline at end of file