Skip to content

Accept cookies#61#62

Open
justin-b-yee wants to merge 26 commits into
mainfrom
accept-cookies#61
Open

Accept cookies#61#62
justin-b-yee wants to merge 26 commits into
mainfrom
accept-cookies#61

Conversation

@justin-b-yee

Copy link
Copy Markdown

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds cookie consent handling, consent persistence, and conditional analytics loading to support user cookie preferences.

Changes:

  • Adds a Consent model, socket API, and tests for storing consent decisions.
  • Adds a React cookie consent component and integrates it into the main app.
  • Removes server-rendered Google Analytics injection and updates CSP/package dependencies for cookie consent assets.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
package.json Adds vanilla-cookieconsent dependency.
package-lock.json Locks the new cookie consent dependency.
app/socket-apis/save-consent.js Adds socket handler for saving consent records.
app/socket-apis/__tests__/save-consent.js Adds tests for the consent socket handler.
app/server/the-civil-server.js Allows the cookie consent stylesheet in CSP.
app/server/routes/set-user-cookie.js Gates synuser cookie behavior on consent.
app/server/routes/server-react-render.jsx Removes server-side Google Analytics injection.
app/models/consent.js Adds consent persistence model and update helpers.
app/models/__tests__/consent.js Adds model tests for consent creation/history.
app/components/enciv-cookies.js Adds cookie consent UI and analytics start/stop logic.
app/components/app.jsx Integrates cookie consent component into the app.
Comments suppressed due to low confidence (2)

app/socket-apis/tests/save-consent.js:53

  • This invocation has the same argument ordering issue: .call(synuser, consentData, cb) does not pass a synuser argument to saveConsent, so the Jest callback is never used and the test will fail before it verifies the update path. Include the socket context and the handler arguments separately.
  await saveConsent.call(
    synuser,
    [
      {
        category: 'ConsentOption2',

app/socket-apis/tests/save-consent.js:91

  • This invocation passes the consent data as the synuser parameter and the Jest mock as formattedConsentData, so the handler calls its default callback rather than cb. To exercise the no-identifier path, pass null as the first function argument after the this context.
  await saveConsent.call(
    null,
    [
      {
        category: 'ConsentOption1',

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/server/routes/set-user-cookie.js Outdated
Comment thread app/components/enciv-cookies.js Outdated
Comment thread app/socket-apis/save-consent.js
Comment thread app/socket-apis/__tests__/save-consent.js

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 15 comments.

Comment thread .env.txt Outdated
Comment thread app/components/enciv-cookies.js Outdated
Comment thread app/components/app.jsx
Comment thread app/models/consent.js Outdated
Comment thread app/socket-apis/save-consent.js Outdated
Comment thread app/socket-apis/__tests__/save-consent.js Outdated
Comment thread app/models/consent.js Outdated
Comment thread app/socket-apis/save-consent.js Outdated
Comment thread app/socket-apis/save-consent.js Outdated
Comment thread app/models/consent.js
@justin-b-yee justin-b-yee force-pushed the accept-cookies#61 branch 2 times, most recently from ef8c7a6 to dd9dd1c Compare June 1, 2026 18:37

@ddfridley ddfridley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments.

Comment thread app/components/app.jsx
Comment on lines +13 to +30
function startAnalytics() {
if (!window.process.env.GOOGLE_ANALYTICS) return
if (document.getElementById('googletagmanager')) return

window.dataLayer = window.dataLayer || []
window.gtag = function () {
window.dataLayer.push(arguments)
}
window.gtag('js', new Date())
window.gtag('config', `${window.process.env.GOOGLE_ANALYTICS}`)

const script = document.createElement('script')
script.src = `https://www.googletagmanager.com/gtag/js?id=${window.process.env.GOOGLE_ANALYTICS}`
script.id = 'googletagmanager'
script.async = true
document.head.appendChild(script)
console.log('Starting analytics')
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment - The BrowserEnv component injects ENV selected vars from the server side to the client side.

Comment thread app/components/enciv-cookies.js
Comment thread app/components/enciv-cookies.js
Comment thread app/models/consent.js Outdated
Comment thread app/models/consent.js
Comment thread app/models/consent.js Outdated
Comment thread app/server/routes/server-react-render.jsx Outdated
Comment thread app/server/routes/set-user-cookie.js Outdated
Comment on lines +34 to +38
if (!hasRequiredCookieConsent(req)) {
res.clearCookie('synuser')
next()
return
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this is good news. We don't need to revoke the synuser cookie. We just need to revoke the cookies for google analytics and other things.

We should also look at enciv-home. It adds cookies for google adds. We need an interface so that Google Ads cookie code can become part of cookie consent with out having to change the code in civil-server.

Comment thread app/socket-apis/save-consent.js Outdated
justin-b-yee and others added 3 commits June 22, 2026 10:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@justin-b-yee

Copy link
Copy Markdown
Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in commit 0a78db5. The only conflict was in app/server/the-civil-server.js — I adopted the new contentSecurityPolicy structure from main while preserving the cookie consent CDN CSS URL in styleSrc.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 8 comments.

Comment thread app/components/enciv-cookies.js Outdated
Comment thread app/models/consent.js Outdated
Comment thread app/server/the-civil-server.js Outdated
Comment on lines +62 to +67
styleSrc: [
"'self'",
"'unsafe-inline'",
'*.googleapis.com',
'https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@3.0.1/dist/cookieconsent.css',
],
Comment thread app/server/routes/set-user-cookie.js Outdated
Comment thread app/components/app.jsx Outdated
Comment thread app/socket-apis/save-consent.js
Comment thread app/socket-apis/save-consent.js Outdated
Comment thread package.json
Comment on lines 106 to +108
"stream-browserify": "^3.0.0",
"superagent": "^5.3.1"
"superagent": "^5.3.1",
"vanilla-cookieconsent": "^3.0.1"
justin-b-yee and others added 3 commits June 22, 2026 11:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 10 comments.

Comment on lines +33 to +50
function stopAnalytics() {
console.log('Stopping analytics')

// Clear Google Analytics cookies for this session
;['_ga', '_gid', '_gat'].forEach(name => {
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`
})

delete window.dataLayer
delete window.gtag
const gtmElement = document.getElementById('googletagmanager')
if (gtmElement) gtmElement.remove()

// Full opt-out requires a browser refresh to prevent GA from re-initializing and setting new cookies
alert('Analytics has been disabled. Please refresh your browser to fully complete the opt-out.')

// Static consent configuration — independent of component state
const modalSections = {
Comment on lines +10 to +28
function parseConsentCookie(consentCookie) {
if (!consentCookie) return undefined
if (typeof consentCookie === 'object') return consentCookie

try {
return JSON.parse(consentCookie)
} catch (error) {
try {
return JSON.parse(decodeURIComponent(consentCookie))
} catch (err) {
return undefined
}
}
}

function hasRequiredCookieConsent(req) {
const consent = parseConsentCookie(req.cookies && req.cookies.cc_cookie)
return !!(consent && Array.isArray(consent.categories) && consent.categories.includes('necessary'))
}
Comment on lines +65 to +70
styleSrc: [
"'self'",
"'unsafe-inline'",
'*.googleapis.com',
'https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@3.0.1/dist/cookieconsent.css',
],
Comment thread app/models/consent.js
Comment on lines +2 to +4
const Joi = require('@hapi/joi')
const { Mongo, Collection } = require('@enciv/mongo-collections')
const { ObjectId } = require('mongodb')
Comment thread app/models/consent.js
Comment on lines +39 to +46
ipAddress: Joi.string()
.ip({
version: ['ipv4', 'ipv6'],
cidr: 'optional',
})
.optional()
.allow(''),
})
Comment thread app/models/consent.js
Comment on lines +116 to +118
} else {
console.log('No document to update provided.')
}
Comment thread app/components/app.jsx
<ErrorBoundary>
<div style={{ position: 'relative' }}>
<Helmet>
<title>{iota?.subject || 'Candiate Conversations'}</title>
},
},
})
})

import Consent from '../models/consent'

async function saveConsent(formattedConsentData, cb = () => {}) {
Comment on lines +46 to +47
return cb({ created: false })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not start analytics or create a cookie until cookies are agreed

4 participants