-
Notifications
You must be signed in to change notification settings - Fork 72
Ahrefs Web Analytics integration #774
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
Open
guillermocalvo
wants to merge
12
commits into
GitbookIO:main
Choose a base branch
from
guillermocalvo:ahrefs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c590ed3
Ahrefs Web Analytics integration
guillermocalvo 4f0cb12
Merge branch 'main' into ahrefs
taranvohra 90a3969
Apply suggestions from code review
guillermocalvo a2ba262
Apply suggestions from code review
guillermocalvo 05e9464
Use a higher-res logo
guillermocalvo 86c0782
Merge branch 'main' into ahrefs
taranvohra efedec7
Bump version and update bun.lock
guillermocalvo ccf651f
Update README.md
guillermocalvo 18d4e00
Create changeset
guillermocalvo 53f2aba
Merge branch 'main' into ahrefs
taranvohra 55de543
Merge branch 'main' into ahrefs
taranvohra f2616a6
Merge branch 'main' into ahrefs
taranvohra 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
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,7 @@ | ||
# @gitbook/integration-ahrefs | ||
|
||
## 0.0.1 | ||
|
||
### Patch Changes | ||
|
||
Added Ahrefs Web Analytics integration. |
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,42 @@ | ||
name: ahrefs | ||
title: Ahrefs | ||
icon: ./assets/icon.png | ||
previewImages: | ||
- ./assets/ahrefs-preview.png | ||
description: Receive GitBook traffic insights directly in your Ahrefs dashboard. | ||
externalLinks: | ||
- label: Documentation | ||
url: https://www.gitbook.com/integrations/ahrefs | ||
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: | ||
- site:script:inject | ||
organization: gitbook | ||
contentSecurityPolicy: | ||
script-src: https://analytics.ahrefs.com | ||
connect-src: analytics.ahrefs.com | ||
summary: | | ||
# Overview | ||
[Ahrefs Web Analytics](https://ahrefs.com/web-analytics) is a privacy-friendly analytics platform that provides you with a simple and free solution to track and report your published sites' traffic. No cookies by default. Just the metrics you need. | ||
|
||
# How it works | ||
The Ahrefs integration allows you to track traffic in your published sites from your Ahrefs dashboard. | ||
|
||
Automatic tracking in your documentation: Each of your connected GitBook sites will fetch the Ahrefs Web Analytics tracking script and inject it in your published content. | ||
|
||
# Configure | ||
Enable the Ahrefs integration by navigating to organization settings. The integration can be enabled on single or multiple sites. | ||
categories: | ||
- analytics | ||
configurations: | ||
site: | ||
properties: | ||
tracking_id: | ||
type: string | ||
title: Tracking ID | ||
description: Look for this in your Ahrefs Web Analytics account. | ||
required: | ||
- tracking_id | ||
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-ahrefs", | ||
"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,38 @@ | ||
import { | ||
createIntegration, | ||
FetchPublishScriptEventCallback, | ||
RuntimeContext, | ||
RuntimeEnvironment, | ||
} from '@gitbook/runtime'; | ||
|
||
import script from './script.raw.js'; | ||
|
||
type AhrefsRuntimeContext = RuntimeContext< | ||
RuntimeEnvironment< | ||
{}, | ||
{ | ||
tracking_id?: string; | ||
} | ||
> | ||
>; | ||
|
||
export const handleFetchEvent: FetchPublishScriptEventCallback = async ( | ||
event, | ||
{ environment }: AhrefsRuntimeContext, | ||
) => { | ||
const trackingId = environment.siteInstallation?.configuration?.tracking_id; | ||
if (!trackingId) { | ||
return; | ||
} | ||
|
||
return new Response((script as string).replace('<TO_REPLACE>', trackingId), { | ||
headers: { | ||
'Content-Type': 'application/javascript', | ||
'Cache-Control': 'max-age=604800', | ||
}, | ||
}); | ||
}; | ||
|
||
export default createIntegration<AhrefsRuntimeContext>({ | ||
fetch_published_script: handleFetchEvent, | ||
}); |
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,10 @@ | ||
(function (win, doc) { | ||
const trackingID = '<TO_REPLACE>'; | ||
const js = doc.createElement('script'); | ||
js.type = 'text/javascript' | ||
js.async = true; | ||
js.src = 'https://analytics.ahrefs.com/analytics.js'; | ||
js.dataset['key'] = trackingID; | ||
guillermocalvo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const first = doc.getElementsByTagName('script')[0]; | ||
first.parentNode.insertBefore(js, first); | ||
})(window, document); |
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.