From be81de1ead77a59fd4db14c68046fff04d767935 Mon Sep 17 00:00:00 2001 From: Addison Date: Tue, 23 Apr 2024 09:14:52 +0900 Subject: [PATCH 1/2] Add boilerplate for zendesk integration --- integrations/zendesk/.eslintrc.json | 3 ++ integrations/zendesk/gitbook-manifest.yaml | 28 ++++++++++++++ integrations/zendesk/package.json | 17 +++++++++ integrations/zendesk/src/index.tsx | 44 ++++++++++++++++++++++ integrations/zendesk/src/script.raw.js | 14 +++++++ integrations/zendesk/tsconfig.json | 6 +++ 6 files changed, 112 insertions(+) create mode 100644 integrations/zendesk/.eslintrc.json create mode 100644 integrations/zendesk/gitbook-manifest.yaml create mode 100644 integrations/zendesk/package.json create mode 100644 integrations/zendesk/src/index.tsx create mode 100644 integrations/zendesk/src/script.raw.js create mode 100644 integrations/zendesk/tsconfig.json diff --git a/integrations/zendesk/.eslintrc.json b/integrations/zendesk/.eslintrc.json new file mode 100644 index 000000000..99e7792b9 --- /dev/null +++ b/integrations/zendesk/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": ["@gitbook/eslint-config/integration"] +} \ No newline at end of file diff --git a/integrations/zendesk/gitbook-manifest.yaml b/integrations/zendesk/gitbook-manifest.yaml new file mode 100644 index 000000000..364eaf86e --- /dev/null +++ b/integrations/zendesk/gitbook-manifest.yaml @@ -0,0 +1,28 @@ +name: zendesk +title: Zendesk +organization: d8f63b60-89ae-11e7-8574-5927d48c4877 +visibility: private +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 diff --git a/integrations/zendesk/package.json b/integrations/zendesk/package.json new file mode 100644 index 000000000..b437f6e71 --- /dev/null +++ b/integrations/zendesk/package.json @@ -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": "*" + } +} \ No newline at end of file diff --git a/integrations/zendesk/src/index.tsx b/integrations/zendesk/src/index.tsx new file mode 100644 index 000000000..09ae162b1 --- /dev/null +++ b/integrations/zendesk/src/index.tsx @@ -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('', trackingId), { + headers: { + 'Content-Type': 'application/javascript', + 'Cache-Control': 'max-age=604800', + }, + }); +}; + +export default createIntegration({ + fetch_published_script: handleFetchEvent, +}); diff --git a/integrations/zendesk/src/script.raw.js b/integrations/zendesk/src/script.raw.js new file mode 100644 index 000000000..48bfff6e6 --- /dev/null +++ b/integrations/zendesk/src/script.raw.js @@ -0,0 +1,14 @@ +(function (h, o, t, j, a, r) { + const trackingID = ''; + h.hj = + h.hj || + function () { + (h.hj.q = h.hj.q || []).push(arguments); + }; + h._hjSettings = { hjid: trackingID, hjsv: 6 }; + a = o.getElementsByTagName('head')[0]; + r = o.createElement('script'); + r.async = 1; + r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv; + a.appendChild(r); +})(window, document, 'WIP', '.js?sv='); diff --git a/integrations/zendesk/tsconfig.json b/integrations/zendesk/tsconfig.json new file mode 100644 index 000000000..f2558f29c --- /dev/null +++ b/integrations/zendesk/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "@gitbook/tsconfig/integration.json", + "compilerOptions": { + "lib": ["ES6", "DOM"], + } +} \ No newline at end of file From 609c5186b147d4e0ffb1e72437207dcf28ec91ba Mon Sep 17 00:00:00 2001 From: Addison Date: Tue, 30 Apr 2024 16:59:24 +0900 Subject: [PATCH 2/2] Commit before publishing testing version --- integrations/zendesk/gitbook-manifest.yaml | 10 +++++++++- integrations/zendesk/src/script.raw.js | 22 +++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/integrations/zendesk/gitbook-manifest.yaml b/integrations/zendesk/gitbook-manifest.yaml index 364eaf86e..282a2d972 100644 --- a/integrations/zendesk/gitbook-manifest.yaml +++ b/integrations/zendesk/gitbook-manifest.yaml @@ -1,7 +1,7 @@ name: zendesk title: Zendesk organization: d8f63b60-89ae-11e7-8574-5927d48c4877 -visibility: private +visibility: public description: '' summary: | # Overview @@ -26,3 +26,11 @@ configurations: 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 diff --git a/integrations/zendesk/src/script.raw.js b/integrations/zendesk/src/script.raw.js index 48bfff6e6..b146409f9 100644 --- a/integrations/zendesk/src/script.raw.js +++ b/integrations/zendesk/src/script.raw.js @@ -1,14 +1,10 @@ -(function (h, o, t, j, a, r) { +(function (z, e, n) { const trackingID = ''; - h.hj = - h.hj || - function () { - (h.hj.q = h.hj.q || []).push(arguments); - }; - h._hjSettings = { hjid: trackingID, hjsv: 6 }; - a = o.getElementsByTagName('head')[0]; - r = o.createElement('script'); - r.async = 1; - r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv; - a.appendChild(r); -})(window, document, 'WIP', '.js?sv='); + 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);