Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zendesk Integration #464

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions integrations/zendesk/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@gitbook/eslint-config/integration"]
}
36 changes: 36 additions & 0 deletions integrations/zendesk/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: zendesk
title: Zendesk
organization: d8f63b60-89ae-11e7-8574-5927d48c4877
visibility: public
description: ''
summary: |
# Overview
https://support.zendesk.com/hc/en-us/articles/4593564000410-Setting-up-the-search-crawler
categories:
- analytics
script: src/index.tsx
scopes:
- space:script:inject
- site:script:inject
blocks:
- id: zendesk
title: Zendesk
description: My GitBook Integration
secrets: {}
configurations:
space:
properties:
site_tag:
type: string
title: Hotjar Site ID
description: Site Tag from Zendesk
required:
- site_tag
site:
properties:
site_tag:
type: string
title: Hotjar Site ID
description: Site Tag from Zendesk
required:
- site_tag
17 changes: 17 additions & 0 deletions integrations/zendesk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "zendesk",
"private": true,
"scripts": {
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
"typecheck": "tsc --noEmit",
"publish": "gitbook publish ."
},
"dependencies": {
"@gitbook/runtime": "*"
},
"devDependencies": {
"@gitbook/cli": "^0.15.1",
"@gitbook/eslint-config": "*",
"@gitbook/tsconfig": "*"
}
}
44 changes: 44 additions & 0 deletions integrations/zendesk/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
createIntegration,
FetchPublishScriptEventCallback,
RuntimeContext,
RuntimeEnvironment,
} from '@gitbook/runtime';

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

type ZendeskRuntimeContext = RuntimeContext<
RuntimeEnvironment<
{},
{
site_tag?: string;
}
>
>;

export const handleFetchEvent: FetchPublishScriptEventCallback = async (
event,
{ environment }: ZendeskRuntimeContext
) => {
const trackingId =
environment.siteInstallation?.configuration?.site_tag ??
environment.spaceInstallation.configuration.site_tag;
if (!trackingId) {
throw new Error(
`The Zendesk site tag is missing from the configuration (ID: ${
'spaceId' in event ? event.spaceId : event.siteId
}).`
);
}

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

export default createIntegration<ZendeskRuntimeContext>({
fetch_published_script: handleFetchEvent,
});
10 changes: 10 additions & 0 deletions integrations/zendesk/src/script.raw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(function (z, e, n) {
const trackingID = '<TO_REPLACE>';
z._trackingID = trackingID;

z = e.getElementsByTagName('head')[0];
n = e.createElement('meta');
n.name = 'zd-site-verification';
n.content = `${z._trackingID}`;
z.appendChild(n);
})(window, document);
6 changes: 6 additions & 0 deletions integrations/zendesk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "@gitbook/tsconfig/integration.json",
"compilerOptions": {
"lib": ["ES6", "DOM"],
}
}
Loading