Skip to content

Commit

Permalink
Add ZoomInfo integration (#647)
Browse files Browse the repository at this point in the history
* init. works

* remove heap refs

* update assets
  • Loading branch information
vibhanshub authored Dec 10, 2024
1 parent e7afee8 commit 0c7d088
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
Binary file added integrations/zoominfo/assets/icon.png
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/zoominfo/assets/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions integrations/zoominfo/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: zoominfo
title: ZoomInfo
icon: ./assets/icon.png
previewImages:
- ./assets/preview.png
description: Plug your GitBook site to your ZoomInfo instance.
externalLinks:
- label: Documentation
url: https://www.gitbook.com/integrations/zoominfo
visibility: private
script: ./src/index.ts
# The following scope(s) are available only to GitBook Staff
# See https://developer.gitbook.com/integrations/configurations#scopes
scopes:
- site:script:inject
organization: gitbook
contentSecurityPolicy:
script-src: https://js.zi-scripts.com 'unsafe-inline';
summary: |
# Overview
This integration allows to add the ZoomInfo Analytics tracker on your published GitBook site.
# How it works
The integration injects the ZoomInfo script on your page, using the script you provide during configuration,
so that you can get analytics information from your GitBook site directly inside of ZoomInfo.
# Configure
Install the integration on the GitBook site of your choice.
Locate the ZoomInfo script you want to use, which is available in WebSights management:
* copy the script and paste it in the GitBook integration's configuration screen
categories:
- analytics
configurations:
site:
properties:
script:
type: string
title: Script
description: Available in your ZoomInfo account
required:
- script
target: site
19 changes: 19 additions & 0 deletions integrations/zoominfo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@gitbook/integration-zoominfo",
"version": "0.0.1",
"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 ."
}
}
53 changes: 53 additions & 0 deletions integrations/zoominfo/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
createIntegration,
FetchPublishScriptEventCallback,
RuntimeContext,
RuntimeEnvironment,
} from '@gitbook/runtime';

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

type ZoomInfoRuntimeContext = RuntimeContext<
RuntimeEnvironment<
{},
{
script?: string;
}
>
>;

export const handleFetchEvent: FetchPublishScriptEventCallback = async (
event,
{ environment }: ZoomInfoRuntimeContext,
) => {
const script = environment.siteInstallation?.configuration?.script;
if (!script) {
throw new Error(
`The ZoomInfo script is missing from the configuration (ID: ${
'spaceId' in event ? event.spaceId : event.siteId
}).`,
);
}
// matches occurances of alphanumeric strings inside single quotes
// of length of exactly 20, which is what we need
const regex = /'[a-f0-9]{20}'/;

const match = script.match(regex);
if (!match) {
throw new Error(`Match for ZoomInfo's site id could not be found`);
}

// match[0] looks like "'abc...'" we need to remove the single quotes
const siteId = match[0].replace(/\'/g, '');

return new Response((rawScript as string).replace('<TO_REPLACE>', siteId), {
headers: {
'Content-Type': 'application/javascript',
'Cache-Control': 'max-age=604800',
},
});
};

export default createIntegration<ZoomInfoRuntimeContext>({
fetch_published_script: handleFetchEvent,
});
10 changes: 10 additions & 0 deletions integrations/zoominfo/src/script.raw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const siteId = '<TO_REPLACE>';

(function (w, d, s) {
w['ZIProjectKey'] = siteId;
var n;
n = d.createElement('script');
n.src = s;
n.async = !0;
d.head.appendChild(n);
})(window, document, 'https://js.zi-scripts.com/zi-tag.js');
3 changes: 3 additions & 0 deletions integrations/zoominfo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@gitbook/tsconfig/integration.json"
}

0 comments on commit 0c7d088

Please sign in to comment.