File tree Expand file tree Collapse file tree 7 files changed +102
-0
lines changed Expand file tree Collapse file tree 7 files changed +102
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ {
2+ "extends" : " @gitbook/tsconfig/base.json" ,
3+ "compilerOptions" : {
4+ "outDir" : " ./dist"
5+ },
6+ "include" : [" src/**/*" ]
7+ }
You can’t perform that action at this time.
0 commit comments