-
Notifications
You must be signed in to change notification settings - Fork 71
Add Pendo integration #643
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
19e40cb
Add Pendo integration
vibhanshub 413da3a
update package
vibhanshub e63f558
lockfile
vibhanshub 220f46b
update script scr
vibhanshub 087bc64
fix pendo eu region thingy
vibhanshub ef39e8a
update assets
vibhanshub f7f6948
update script in manifest
vibhanshub 74d85b1
add preview images
vibhanshub 6758045
add var
vibhanshub 7b86da4
typo
vibhanshub 2df543b
typo
vibhanshub 3bead83
Merge remote-tracking branch 'origin' into vib/add-pendo
vibhanshub 5cd3e2c
update bun.lockb
vibhanshub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: pendo | ||
title: Pendo | ||
icon: ./assets/icon.png | ||
previewImages: | ||
- ./assets/preview-1.png | ||
- ./assets/preview-2.png | ||
description: Plug your GitBook site to your Pendo Analytics instance. | ||
externalLinks: | ||
- label: Documentation | ||
url: https://www.gitbook.com/integrations/pendo | ||
visibility: private | ||
script: ./src/index.tsx | ||
# 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://cdn.eu.pendo.io https://cdn.pendo.io | ||
summary: | | ||
# Overview | ||
This integration allows to add Pendo Analytics on your published GitBook site. | ||
|
||
# How it works | ||
The integration injects the Pendo Analytics script on your page, using the configured API Key, | ||
so that you can get analytics information from your GitBook site directly inside of Pendo. | ||
|
||
# Configure | ||
Install the integration on the GitBook site of your choice. | ||
Locate the Pendo API Key you want to use from Pendo and paste it in the GitBook integration's configuration screen | ||
|
||
categories: | ||
- analytics | ||
configurations: | ||
site: | ||
componentId: config | ||
target: site |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@gitbook/integration-pendo", | ||
"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 ." | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { | ||
createIntegration, | ||
FetchPublishScriptEventCallback, | ||
RuntimeContext, | ||
RuntimeEnvironment, | ||
createComponent, | ||
} from '@gitbook/runtime'; | ||
import { IntegrationInstallationConfiguration } from '@gitbook/api'; | ||
|
||
import script from './script.raw.js'; | ||
|
||
type PendoRuntimeContext = RuntimeContext< | ||
RuntimeEnvironment<{}, PendoSiteInstallationConfiguration> | ||
>; | ||
type PendoRuntimeEnvironment = RuntimeEnvironment<{}, PendoSiteInstallationConfiguration>; | ||
|
||
type PendoSiteInstallationConfiguration = { | ||
api_key?: string; | ||
is_eu_region?: boolean; | ||
}; | ||
|
||
type PendoState = PendoSiteInstallationConfiguration; | ||
|
||
type PendoProps = { | ||
installation: { | ||
configuration?: IntegrationInstallationConfiguration; | ||
}; | ||
siteInstallation?: { | ||
configuration?: PendoSiteInstallationConfiguration; | ||
}; | ||
}; | ||
export type PendoAction = { action: 'save.config' }; | ||
|
||
const configBlock = createComponent<PendoProps, PendoState, PendoAction, PendoRuntimeContext>({ | ||
componentId: 'config', | ||
initialState: (props) => { | ||
const siteInstallation = props.siteInstallation; | ||
return { | ||
api_key: siteInstallation?.configuration?.api_key || '', | ||
is_eu_region: siteInstallation?.configuration?.is_eu_region || false, | ||
}; | ||
}, | ||
action: async (element, action, context) => { | ||
switch (action.action) { | ||
case 'save.config': | ||
const { api, environment } = context; | ||
const siteInstallation = assertSiteInstallation(environment); | ||
|
||
const configurationBody = { | ||
...siteInstallation.configuration, | ||
api_key: element.state.api_key, | ||
is_eu_region: element.state.is_eu_region, | ||
}; | ||
|
||
await api.integrations.updateIntegrationSiteInstallation( | ||
siteInstallation.integration, | ||
siteInstallation.installation, | ||
siteInstallation.site, | ||
{ | ||
configuration: { | ||
...configurationBody, | ||
}, | ||
}, | ||
); | ||
|
||
return { type: 'complete' }; | ||
} | ||
}, | ||
render: async (element, context) => { | ||
return ( | ||
<configuration> | ||
<box> | ||
<markdown content="### Pendo Analytics" /> | ||
<vstack> | ||
<input | ||
label="Pendo API Key" | ||
hint={<text>The Pendo API Key.</text>} | ||
element={<textinput state="api_key" placeholder="API Key" />} | ||
/> | ||
</vstack> | ||
<divider size="medium" /> | ||
|
||
<markdown content="### Region of your Pendo App" /> | ||
<input | ||
label="Is your app in the EU Region" | ||
hint="Toggle on if your app is in EU Region" | ||
element={<switch state="is_eu_region" />} | ||
/> | ||
|
||
<input | ||
label="" | ||
hint="" | ||
element={ | ||
<button | ||
style="primary" | ||
disabled={false} | ||
label="Save" | ||
tooltip="Save configuration" | ||
onPress={{ | ||
action: 'save.config', | ||
}} | ||
/> | ||
} | ||
/> | ||
</box> | ||
</configuration> | ||
); | ||
}, | ||
}); | ||
|
||
function assertSiteInstallation(environment: PendoRuntimeEnvironment) { | ||
const siteInstallation = environment.siteInstallation; | ||
if (!siteInstallation) { | ||
throw new Error('No site installation found'); | ||
} | ||
|
||
return siteInstallation; | ||
} | ||
|
||
export const handleFetchEvent: FetchPublishScriptEventCallback = async ( | ||
event, | ||
{ environment }: PendoRuntimeContext, | ||
) => { | ||
const apiKey = environment.siteInstallation?.configuration?.api_key; | ||
const isEURegion = environment.siteInstallation?.configuration?.is_eu_region; | ||
if (!apiKey) { | ||
throw new Error( | ||
`The API key is missing from the configuration (ID: ${ | ||
'spaceId' in event ? event.spaceId : event.siteId | ||
}).`, | ||
); | ||
} | ||
const region = isEURegion ? 'EU' : 'US'; | ||
return new Response( | ||
(script as string).replace('<TO_REPLACE>', apiKey).replace('<REGION>', region), | ||
{ | ||
headers: { | ||
'Content-Type': 'application/javascript', | ||
'Cache-Control': 'max-age=604800', | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
export default createIntegration<PendoRuntimeContext>({ | ||
fetch_published_script: handleFetchEvent, | ||
components: [configBlock], | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(function (apiKey) { | ||
(function (p, e, n, d, o) { | ||
var v, w, x, y, z; | ||
o = p[d] = p[d] || {}; | ||
o._q = o._q || []; | ||
v = ['initialize', 'identify', 'updateOptions', 'pageLoad', 'track']; | ||
for (w = 0, x = v.length; w < x; ++w) | ||
(function (m) { | ||
o[m] = | ||
o[m] || | ||
function () { | ||
o._q[m === v[0] ? 'unshift' : 'push']( | ||
[m].concat([].slice.call(arguments, 0)), | ||
); | ||
}; | ||
})(v[w]); | ||
y = e.createElement(n); | ||
y.async = !0; | ||
var cdn; | ||
cdn = '<REGION>' === 'EU' ? 'https://cdn.eu.pendo.io' : 'https://cdn.pendo.io'; | ||
vibhanshub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
y.src = `${cdn}/agent/static/` + apiKey + '/pendo.js'; | ||
z = e.getElementsByTagName(n)[0]; | ||
z.parentNode.insertBefore(y, z); | ||
})(window, document, 'script', 'pendo'); | ||
})('<TO_REPLACE>'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@gitbook/tsconfig/integration.json" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.