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 Mouseflow integration #412

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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/mouseflow/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@gitbook/eslint-config/integration"]
}
1 change: 1 addition & 0 deletions integrations/mouseflow/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @gitbook/integration-mouseflow
Binary file added integrations/mouseflow/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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions integrations/mouseflow/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: mouseflow
title: mouseflow
icon: ./assets/icon.png
previewImages:
- ./assets/mouseflow-preview.png
description: Plug your GitBook site to your Mouseflow installation.
externalLinks:
- label: Documentation
url: https://www.gitbook.com/integrations/mouseflow
visibility: public
script: ./src/index.ts
# The following scope(s) are available only to GitBook Staff
# See https://developer.gitbook.com/integrations/configurations#scopes
scopes:
- space:script:inject
organization: d8f63b60-89ae-11e7-8574-5927d48c4877
contentSecurityPolicy:
script-src: cdn.mouseflow.com;
summary: |
# Overview
This integration allows to add the Mouseflow tracker on your published GitBook site.

# How it works
The integration injects the Mouseflow script on your page, using the configured Website ID,
so that you can get analytics information from your GitBook site.

# Configure
Install the integration on the GitBook space of your choice.
Locate the Website ID you want to use from the settings page.

categories:
- analytics
configurations:
space:
properties:
website_id:
type: string
title: Mouseflow Website ID
description: Available in Mouseflow website settings page
required:
- website_id
18 changes: 18 additions & 0 deletions integrations/mouseflow/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@gitbook/integration-mouseflow",
"version": "0.0.1",
"private": true,
"dependencies": {
"@gitbook/api": "*",
"@gitbook/runtime": "*"
},
"devDependencies": {
"@gitbook/cli": "*"
},
"scripts": {
"lint": "eslint ./src/**/*.ts",
"typecheck": "tsc --noEmit",
"publish-integrations-staging": "gitbook publish .",
"publish-integrations": "gitbook publish ."
}
}
40 changes: 40 additions & 0 deletions integrations/mouseflow/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
createIntegration,
FetchPublishScriptEventCallback,
RuntimeContext,
RuntimeEnvironment,
} from '@gitbook/runtime';

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

type MouseflowRuntimeContext = RuntimeContext<
RuntimeEnvironment<
{},
{
website_id?: string;
}
>
>;

export const handleFetchEvent: FetchPublishScriptEventCallback = async (
event,
{ environment }: MouseflowRuntimeContext
) => {
const websiteId = environment.spaceInstallation.configuration.website_id;
if (!websiteId) {
throw new Error(
`The Mouseflow Website ID is missing from the configuration. (ID: ${event.spaceId}).`
);
}

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

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

window._mfq = window._mfq || [];
(function() {
var mf = document.createElement("script");
mf.type = "text/javascript";
mf.defer = true;
mf.src = "//cdn.mouseflow.com/projects/" + websiteId + ".js";
document.getElementsByTagName("head")[0].appendChild(mf);
})();
3 changes: 3 additions & 0 deletions integrations/mouseflow/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@gitbook/tsconfig/integration.json"
}