Skip to content

Commit e5a336e

Browse files
Add hubspot integration with updated sites permissions
1 parent a506385 commit e5a336e

File tree

9 files changed

+142
-0
lines changed

9 files changed

+142
-0
lines changed

integrations/hubspot/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@gitbook/eslint-config/integration"]
3+
}

integrations/hubspot/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# @gitbook/integration-hubspot
2+
3+
## 1.0.0
4+
5+
### Major Changes
6+
7+
### Minor Changes
8+
9+
### Patch Changes
1.28 MB
Loading

integrations/hubspot/assets/icon.png

24.4 KB
Loading
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: gitbook-hubspot
2+
title: HubSpot
3+
icon: ./assets/icon.png
4+
previewImages:
5+
- ./assets/hubspot-preview.png
6+
organization: d8f63b60-89ae-11e7-8574-5927d48c4877
7+
description: Plug your GitBook site to your HubSpot installation.
8+
visibility: public
9+
previewImages:
10+
script: ./src/index.ts
11+
# The following scope(s) are available only to GitBook Staff
12+
# See https://developer.gitbook.com/integrations/configurations#scopes
13+
scopes:
14+
- space:script:inject
15+
- site:script:inject
16+
contentSecurityPolicy:
17+
script-src: hsadspixel.net hs-banner.com hs-analytics.net hs-scripts.com;
18+
summary: |
19+
# Overview
20+
This integration allows to add the HubSpot tracking code on your published GitBook site.
21+
22+
# How it works
23+
The integration injects the HubSpot script on your page, using the configured environment ID,
24+
so that you can get analytics information from your GitBook site directly inside of Heap.
25+
26+
# Configure
27+
Install the integration on the GitBook space of your choice.
28+
Locate the HubSpot Script Loader ID you want to use, which is available in HubSpot's Reports & Analytics Tracking section.
29+
30+
The ID should be just the id - "//js.hs-scripts.com/{hubspot_id}.js". (i.e. only paste what you see in hubspot_id)
31+
categories:
32+
- analytics
33+
configurations:
34+
space:
35+
properties:
36+
script_loader_url:
37+
type: string
38+
title: HubSpot Script Loader URL
39+
description: The URL to load the script from. Copied form HubSpot's script tracking code script tag src attribute
40+
required:
41+
- script_loader_url
42+
site:
43+
properties:
44+
script_loader_url:
45+
type: string
46+
title: HubSpot Script Loader URL
47+
description: The URL to load the script from. Copied form HubSpot's script tracking code script tag src attribute
48+
required:
49+
- script_loader_url

integrations/hubspot/package.json

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

integrations/hubspot/src/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 HubSpotRuntimeContext = RuntimeContext<
11+
RuntimeEnvironment<
12+
{},
13+
{
14+
script_loader_url?: string;
15+
}
16+
>
17+
>;
18+
19+
export const handleFetchEvent: FetchPublishScriptEventCallback = (
20+
event,
21+
{ environment }: HubSpotRuntimeContext
22+
) => {
23+
const scriptLoaderURL =
24+
environment.siteInstallation?.configuration?.script_loader_url ??
25+
environment.spaceInstallation.configuration.script_loader_url;
26+
27+
if (!scriptLoaderURL) {
28+
throw new Error(
29+
`The HubSpot Script Loader URL is missing from the configuration (ID: ${event.spaceId}).`
30+
);
31+
}
32+
33+
return new Response(script.replace('<TO_REPLACE_SCRIPT_LOADER_ID>', scriptLoaderURL), {
34+
headers: {
35+
'Content-Type': 'application/javascript',
36+
'Cache-Control': 'max-age=604800',
37+
},
38+
});
39+
};
40+
41+
export default createIntegration<HubSpotRuntimeContext>({
42+
fetch_published_script: handleFetchEvent,
43+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(function (h, u, b, s, p, o, t) {
2+
if (!u.getElementById(b)) {
3+
const trackingID = '<TO_REPLACE_SCRIPT_LOADER_ID>';
4+
5+
const scriptLoaderURL = '//js.hs-scripts.com/' + trackingID + '.js';
6+
s = u.getElementsByTagName('head')[0];
7+
p = u.createElement('script');
8+
p.src = scriptLoaderURL;
9+
p.type = 'text/javascript';
10+
p.id = b;
11+
p.async = 1;
12+
p.defer = 1;
13+
s.appendChild(p);
14+
o = h._hsp = h._hsp || [];
15+
o.push(['setContentType', 'knowledge-article']);
16+
}
17+
})(window, document, 'hs-script-loader');

integrations/hubspot/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@gitbook/tsconfig/integration.json"
3+
}

0 commit comments

Comments
 (0)