Skip to content

Commit edd3d8f

Browse files
add wistia integration support
1 parent 81949ad commit edd3d8f

File tree

7 files changed

+102
-0
lines changed

7 files changed

+102
-0
lines changed
Lines changed: 4 additions & 0 deletions
Loading
408 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: wistia
2+
title: Wistia
3+
icon: ./assets/icon.svg
4+
previewImages:
5+
- ./assets/wistia-preview.png
6+
description: Add Wistia video analytics to your GitBook site.
7+
visibility: public
8+
script: ./src/index.ts
9+
scopes:
10+
- site:script:inject
11+
- site:script:cookies
12+
organization: gitbook
13+
contentSecurityPolicy:
14+
script-src: https://fast.wistia.com;
15+
summary: |
16+
# Overview
17+
This integration adds the Wistia analytics script to your published GitBook site.
18+
19+
# How it works
20+
The integration injects the Wistia script (https://fast.wistia.com/assets/external/E-v1.js)
21+
on your page to enable video analytics tracking.
22+
23+
categories:
24+
- analytics
25+
target: site

integrations/wistia/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@gitbook/integration-wistia",
3+
"version": "1.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"@gitbook/api": "*",
7+
"@gitbook/runtime": "*"
8+
},
9+
"devDependencies": {
10+
"@gitbook/cli": "workspace:*",
11+
"@gitbook/tsconfig": "workspace:*"
12+
},
13+
"scripts": {
14+
"typecheck": "tsc --noEmit",
15+
"publish-integrations-staging": "gitbook publish .",
16+
"check": "gitbook check",
17+
"publish-integrations": "gitbook publish ."
18+
}
19+
}

integrations/wistia/src/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
createIntegration,
3+
FetchPublishScriptEventCallback,
4+
RuntimeContext,
5+
RuntimeEnvironment,
6+
} from '@gitbook/runtime';
7+
8+
import script from './script.raw.js';
9+
10+
type WistiaRuntimeContext = RuntimeContext<RuntimeEnvironment<{}, {}>>;
11+
12+
export const handleFetchEvent: FetchPublishScriptEventCallback = async () => {
13+
return new Response(script as string, {
14+
headers: {
15+
'Content-Type': 'application/javascript',
16+
'Cache-Control': 'max-age=604800',
17+
},
18+
});
19+
};
20+
21+
export default createIntegration<WistiaRuntimeContext>({
22+
fetch_published_script: handleFetchEvent,
23+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const GRANTED_COOKIE = '__gitbook_cookie_granted';
2+
3+
function getCookie(cname) {
4+
const name = `${cname}=`;
5+
const decodedCookie = decodeURIComponent(document.cookie);
6+
const ca = decodedCookie.split(';');
7+
for (let i = 0; i < ca.length; i++) {
8+
let c = ca[i];
9+
while (c.charAt(0) === ' ') {
10+
c = c.substring(1);
11+
}
12+
if (c.indexOf(name) === 0) {
13+
return c.substring(name.length, c.length);
14+
}
15+
}
16+
return '';
17+
}
18+
19+
if (getCookie(GRANTED_COOKIE) === 'yes') {
20+
const script = document.createElement('script');
21+
script.src = 'https://fast.wistia.com/assets/external/E-v1.js';
22+
script.async = true;
23+
document.head.appendChild(script);
24+
}

integrations/wistia/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@gitbook/tsconfig/base.json",
3+
"compilerOptions": {
4+
"outDir": "./dist"
5+
},
6+
"include": ["src/**/*"]
7+
}

0 commit comments

Comments
 (0)