Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions integrations/wistia/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added integrations/wistia/assets/wistia-preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions integrations/wistia/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions integrations/wistia/package.json
Original file line number Diff line number Diff line change
@@ -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 ."
}
}
23 changes: 23 additions & 0 deletions integrations/wistia/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
createIntegration,
FetchPublishScriptEventCallback,
RuntimeContext,
RuntimeEnvironment,
} from '@gitbook/runtime';

import script from './script.raw.js';

type WistiaRuntimeContext = RuntimeContext<RuntimeEnvironment<{}, {}>>;

export const handleFetchEvent: FetchPublishScriptEventCallback = async () => {
return new Response(script as string, {
headers: {
'Content-Type': 'application/javascript',
'Cache-Control': 'max-age=604800',
},
});
};

export default createIntegration<WistiaRuntimeContext>({
fetch_published_script: handleFetchEvent,
});
24 changes: 24 additions & 0 deletions integrations/wistia/src/script.raw.js
Original file line number Diff line number Diff line change
@@ -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);
}
7 changes: 7 additions & 0 deletions integrations/wistia/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@gitbook/tsconfig/base.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["src/**/*"]
}
Loading