Repository navigation
[PRO-4275] Enforce docs analytics consent with Fern 5.169.0 #1405
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
haotian-vapi
wants to merge
1
commit into
main
Choose a base branch
from
haotian/PRO-4275-docs-consent
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.
+976
−129
Open
Changes from all commits
Commits
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
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
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
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
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,58 @@ | ||
| // Necessary Vapi API requests still run when optional collection is denied. | ||
| // Stamp only the audited API origins, at dispatch, without modifying auth, | ||
| // credentials, body, signal, or other caller headers. | ||
| (function () { | ||
| if (window.__vapiDocsConsentRequests) return; | ||
| window.__vapiDocsConsentRequests = true; | ||
| function applicable(input) { | ||
| try { | ||
| var url = new URL(typeof input === 'string' || input instanceof URL ? input : input.url, window.location.href); | ||
| return url.origin === 'https://api.vapi.ai' || url.origin === 'https://api.eu.vapi.ai'; | ||
| } catch (_) { return false; } | ||
| } | ||
| function values() { | ||
| var state = window.vapiDocsConsent && window.vapiDocsConsent.getSnapshot(); | ||
| return { | ||
| 'X-Vapi-Consent-Analytics': state && state.ready && state.analytics ? 'granted' : 'denied', | ||
| 'X-Vapi-Consent-Marketing': state && state.ready && state.marketing ? 'granted' : 'denied' | ||
| }; | ||
| } | ||
| if (typeof window.fetch === 'function') { | ||
| var fetch = window.fetch; | ||
| window.fetch = function (input, init) { | ||
| if (!applicable(input)) return fetch.call(this, input, init); | ||
| var source = init && init.headers !== undefined ? init.headers : input && input.headers; | ||
| var headers = new Headers(source); | ||
| var consent = values(); | ||
| Object.keys(consent).forEach(function (name) { headers.set(name, consent[name]); }); | ||
| return fetch.call(this, input, Object.assign({}, init, { headers: headers })); | ||
| }; | ||
| } | ||
| if (typeof XMLHttpRequest !== 'undefined') { | ||
| var targets = new WeakMap(); | ||
| var open = XMLHttpRequest.prototype.open; | ||
| var setHeader = XMLHttpRequest.prototype.setRequestHeader; | ||
| var send = XMLHttpRequest.prototype.send; | ||
| XMLHttpRequest.prototype.open = function () { | ||
| // open() can synchronously fire readystatechange; callers may send from | ||
| // that callback, so classify before entering the native method. | ||
| targets.set(this, applicable(arguments[1])); | ||
| try { return open.apply(this, arguments); } | ||
| catch (error) { targets.delete(this); throw error; } | ||
| }; | ||
| XMLHttpRequest.prototype.setRequestHeader = function (name, value) { | ||
| // These two reserved headers are adapter-owned. Avoid XHR appending a | ||
| // stale caller grant to the current value supplied immediately at send. | ||
| if (targets.get(this) && /^x-vapi-consent-(analytics|marketing)$/i.test(name)) return; | ||
| return setHeader.call(this, name, value); | ||
| }; | ||
| XMLHttpRequest.prototype.send = function () { | ||
| if (targets.get(this)) { | ||
| var consent = values(); | ||
| var xhr = this; | ||
| Object.keys(consent).forEach(function (name) { setHeader.call(xhr, name, consent[name]); }); | ||
| } | ||
| return send.apply(this, arguments); | ||
| }; | ||
| } | ||
| })(); | ||
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,86 @@ | ||
| // Necessary consent control only. Optional SDKs must use this snapshot; do not | ||
| // add loaders here without verified startup-race and withdrawal controls. | ||
| (function () { | ||
| if (window.vapiDocsConsent) return; | ||
|
|
||
| var snapshot = Object.freeze({ ready: false, analytics: false, marketing: false, personalization: false, generation: 0 }); | ||
| var listeners = new Set(); | ||
| var pendingDenials = {}; | ||
| var fernGranted = false; | ||
| var fernWithdrawn = false; | ||
| window.fernAnalyticsConsent = false; | ||
|
|
||
| // This adapter is the only application Google-consent writer. The Osano | ||
| // automatic bridge must be disabled in the release configuration (runbook). | ||
| window.dataLayer = window.dataLayer || []; | ||
| function googleConsent(command, state) { | ||
| function gtag() { window.dataLayer.push(arguments); } | ||
| gtag('consent', command, { | ||
| analytics_storage: state.analytics ? 'granted' : 'denied', | ||
| ad_storage: state.marketing ? 'granted' : 'denied', | ||
| ad_user_data: state.marketing ? 'granted' : 'denied', | ||
| ad_personalization: state.marketing ? 'granted' : 'denied', | ||
| personalization_storage: state.personalization ? 'granted' : 'denied' | ||
| }); | ||
| } | ||
| googleConsent('default', snapshot); | ||
|
|
||
| window.vapiDocsConsent = Object.freeze({ | ||
| getSnapshot: function () { return snapshot; }, | ||
| subscribe: function (listener) { | ||
| listeners.add(listener); | ||
| return function () { listeners.delete(listener); }; | ||
| } | ||
| }); | ||
|
|
||
| function readConsent() { | ||
| try { return window.Osano.cm.getConsent(); } catch (_) { return undefined; } | ||
| } | ||
| function valid(value) { return value === 'ACCEPT' || value === 'DENY'; } | ||
| function reconcile(consent) { | ||
| consent = consent || readConsent(); | ||
| if (consent) consent = Object.assign({}, consent, pendingDenials); | ||
| var ready = !!consent && valid(consent.ANALYTICS) && valid(consent.MARKETING) && valid(consent.PERSONALIZATION); | ||
| var next = { | ||
| ready: ready, | ||
| analytics: ready && consent.ANALYTICS === 'ACCEPT', | ||
| marketing: ready && consent.MARKETING === 'ACCEPT' && consent['OPT-OUT'] !== 'ACCEPT' && consent.OPT_OUT !== 'ACCEPT' && navigator.globalPrivacyControl !== true, | ||
| personalization: ready && consent.PERSONALIZATION === 'ACCEPT', | ||
| generation: snapshot.generation + 1 | ||
| }; | ||
| if (next.ready === snapshot.ready && next.analytics === snapshot.analytics && next.marketing === snapshot.marketing && next.personalization === snapshot.personalization) return; | ||
| snapshot = Object.freeze(next); | ||
| // Fern's native gate reads the property, not event.detail. Latch withdrawal | ||
| // even during SDK import/idle startup: no regrant on this page after a grant. | ||
| if (fernGranted && !next.analytics) fernWithdrawn = true; | ||
| var allowFern = next.analytics && !fernWithdrawn; | ||
| if (allowFern) fernGranted = true; | ||
| window.fernAnalyticsConsent = allowFern; | ||
| window.dispatchEvent(new Event('fern-analytics-consent')); | ||
| googleConsent('update', next); | ||
| listeners.forEach(function (listener) { listener(snapshot); }); | ||
| } | ||
|
|
||
| // Official preload queue closes the late-CMP race without a polling timeout. | ||
| window.Osano = window.Osano || function () { window.Osano.data.push(arguments); }; | ||
| window.Osano.data = window.Osano.data || []; | ||
| window.Osano('onInitialized', reconcile); | ||
| window.Osano('onConsentSaved', function (consent) { | ||
| pendingDenials = {}; | ||
| reconcile(consent); | ||
| }); | ||
| window.Osano('onOptOut', function () { reconcile(); }); | ||
| window.Osano('onConsentChanged', function (change) { | ||
| // Unsaved acceptance is not a grant. A toggle to denial takes effect now, | ||
| // even if getConsent() still reports the last saved state. | ||
| var consent = readConsent(); | ||
| if (change && consent) { | ||
| ['ANALYTICS', 'MARKETING', 'PERSONALIZATION'].forEach(function (category) { | ||
| if (change[category] === 'DENY') pendingDenials[category] = 'DENY'; | ||
| }); | ||
| if (change['OPT-OUT'] === 'ACCEPT') pendingDenials['OPT-OUT'] = 'ACCEPT'; | ||
| if (change.OPT_OUT === 'ACCEPT') pendingDenials.OPT_OUT = 'ACCEPT'; | ||
| } | ||
| reconcile(consent); | ||
| }); | ||
| })(); |
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
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 |
|---|---|---|
|
|
@@ -30,10 +30,17 @@ experimental: | |
| mdx-components: | ||
| - snippets | ||
| settings: | ||
| require-analytics-consent: true | ||
| http-snippets: false | ||
| dark-mode-code: true | ||
| css: assets/styles.css | ||
| js: | ||
| - path: ./assets/privacy.js | ||
| strategy: beforeInteractive | ||
| - url: https://cmp.osano.com/18N6QTUelY/9fd9583a-77ec-4ecf-a147-069f96fcb514/osano.js | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same Osano config as vapi.ai and the dashboard, so docs pick up the owner's strict-mode, region and discovery changes too. Please re-run the browser suite on the preview after those are published, since the results here were against the current config. |
||
| strategy: beforeInteractive | ||
| - path: ./assets/privacy-requests.js | ||
| strategy: beforeInteractive | ||
| - path: ./assets/close-playground.js | ||
| - path: ./custom.js | ||
| navbar-links: | ||
|
|
@@ -96,8 +103,6 @@ analytics: | |
| posthog: | ||
| api-key: ${POSTHOG_PROJECT_API_KEY} | ||
| endpoint: https://us.i.posthog.com | ||
| ga4: | ||
| measurement-id: G-BVPB7XB842 | ||
| navigation: | ||
| - tab: documentation | ||
| layout: | ||
|
|
||
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "organization": "vapi", | ||
| "version": "5.151.1" | ||
| "version": "5.169.0" | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two origins now get
X-Vapi-Consent-Analytics/X-Vapi-Consent-Marketingon every fetch and XHR, so the browser sends an OPTIONS preflight first. Please confirm on the docs preview that a playground call to each origin passes preflight in production (a screenshot of the network tab or the Playwright request log is enough). If either rejects the headers, the fix is on the API side before this merges, not here.