From 9f601d58971088ad1a9957a6eda99bd08a46e26d Mon Sep 17 00:00:00 2001 From: Sneh1999 Date: Wed, 6 Dec 2023 09:57:32 -0500 Subject: [PATCH] Turn off advertising sharing if do not track enabled --- .codeflow.yml | 9 ++++ .github/ISSUE_TEMPLATE/bug_report.yml | 50 +++++++++++++++++++ .../ISSUE_TEMPLATE/documentation_request.yml | 16 ++++++ .github/ISSUE_TEMPLATE/feature_request.yml | 36 +++++++++++++ .github/workflows/node.js.yml | 29 +++++++++++ .../src/components/CookieBanner.tsx | 20 ++++++++ packages/cb-cookie-banner/src/constants.ts | 3 ++ packages/cb-cookie-manager/src/index.ts | 1 + 8 files changed, 164 insertions(+) create mode 100644 .codeflow.yml create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/documentation_request.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/workflows/node.js.yml diff --git a/.codeflow.yml b/.codeflow.yml new file mode 100644 index 0000000..181d0d9 --- /dev/null +++ b/.codeflow.yml @@ -0,0 +1,9 @@ +secure: + codeowners_enabled: true + codeowners_allow_admin_override: true + codeowners_slack_channel_required: false + required_reviews: 1 + requires_mfa: true + branches: + - main + auto_assign_reviewers: true diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..7464368 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,50 @@ +name: Bug report +description: Create a report to help us improve +title: 'Bug: ' +labels: ['type: bug'] + +body: + - type: input + id: description + attributes: + label: Describe the bug + description: A clear and concise description of what the bug is. + placeholder: Tell us what you see! + validations: + required: true + + - type: textarea + id: steps + attributes: + label: Steps + description: Steps to reproduce the behavior. + placeholder: | + 1. Go to '...' + 2. Click on '....' + 3. Scroll down to '....' + 4. See error + validations: + required: true + + - type: textarea + id: expected + attributes: + label: Expected behavior + description: A clear and concise description of what you expected to happen. + validations: + required: true + + - type: textarea + id: additional + attributes: + label: Additional info + description: If applicable, include links to screenshots or error logs + + - type: textarea + id: environment + attributes: + label: Environment + description: Please fill in details for bugs reported in your environment + placeholder: | + - OS: [e.g. Fedora] + - Version [e.g. 37] diff --git a/.github/ISSUE_TEMPLATE/documentation_request.yml b/.github/ISSUE_TEMPLATE/documentation_request.yml new file mode 100644 index 0000000..6fd6052 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation_request.yml @@ -0,0 +1,16 @@ +name: Documentation request +description: Suggest a documentation for this project +title: 'Documentation Request: ' +labels: ['type: documentation'] + +body: + - type: markdown + attributes: + value: | + This issue form is for documentation requests only! + If you've found a bug, please use [bug_report](/new?template=bug_report.yml) + - type: textarea + id: problem + attributes: + label: Is your documentation request related to a problem? Please describe. + description: A clear and concise description of what the problem is. Ex. It's not clear when [...] diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..b9f535f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,36 @@ +name: Feature request +description: Suggest an idea for this project +title: 'Feature Request: ' +labels: ['type: enhancement'] + +body: + - type: markdown + attributes: + value: | + This issue form is for feature requests only! + If you've found a bug, please use [bug_report](/new?template=bug_report.yml) + - type: textarea + id: problem + attributes: + label: Is your feature request related to a problem? Please describe. + description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + + - type: textarea + id: solution + attributes: + label: Describe the solution you'd like + description: A clear and concise description of what you want to happen. + validations: + required: true + + - type: textarea + id: alternatives + attributes: + label: Describe alternatives you've considered + description: Describe any alternative solutions or features you've considered. + + - type: textarea + id: other + attributes: + label: Additional context + description: Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..ae8165e --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,29 @@ +# This workflow will do a clean installation of node dependencies, +# cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Node.js CI +on: + push: + branches: ['main'] + pull_request: + branches: ['main'] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install dependencies + run: npm install + - name: Lint Check + # When fails, please run "npm run lint" to your code + run: npm run lint diff --git a/packages/cb-cookie-banner/src/components/CookieBanner.tsx b/packages/cb-cookie-banner/src/components/CookieBanner.tsx index dfbe999..e137acc 100644 --- a/packages/cb-cookie-banner/src/components/CookieBanner.tsx +++ b/packages/cb-cookie-banner/src/components/CookieBanner.tsx @@ -1,8 +1,10 @@ import { getDefaultTrackingPreference, + getDomainWithoutSubdomain, isOptOut, persistMobileAppPreferences, Region, + useCookie, useSavedTrackingPreference, useSavedTrackingPreferenceFromMobileApp, useSetTrackingPreference, @@ -10,6 +12,7 @@ import { } from 'cb-cookie-manager'; import React, { memo, useCallback, useEffect, useState } from 'react'; +import { EXPIRATION_DAYS } from '../constants'; import defaultTheme from '../utils/defaultTheme'; import BannerContent from './CookieBannerContent'; import CookiePreferencesModal from './CookiePreferencesModal'; @@ -24,6 +27,12 @@ type Props = { | undefined; }; +const cookieOptions = { + expires: EXPIRATION_DAYS, + domain: getDomainWithoutSubdomain(), + path: '/', +}; + export const useBanner = () => { const savedPreference = useSavedTrackingPreference(); const mobileAppPreference = useSavedTrackingPreferenceFromMobileApp(); @@ -34,6 +43,7 @@ export const useBanner = () => { const optOutRegion = isOptOut(region); const defaultPreferences = getDefaultTrackingPreference(region, config); const setTrackingPreference = useSetTrackingPreference(); + const [, setAdvertisingSharingAllowedCookie] = useCookie('ADVERTISING_SHARING_ALLOWED'); const handleBannerDismiss = useCallback(() => { // Only set default tracking preferences on dismiss if we are in an opt out @@ -65,6 +75,16 @@ export const useBanner = () => { if (shouldSaveMobileAppPreferences && mobileAppPreference) { // Set the is_mobile_app cookie. persistMobileAppPreferences(); + // advertising sharing disabled, if `is_mobile_app` is set + const isEnabled = false; + const updatedAt = Date.now(); + setAdvertisingSharingAllowedCookie( + { + value: isEnabled, + updatedAt, + }, + cookieOptions + ); // Set the cookie banner preferences. setTrackingPreference(mobileAppPreference); } diff --git a/packages/cb-cookie-banner/src/constants.ts b/packages/cb-cookie-banner/src/constants.ts index b92078a..40a55cb 100644 --- a/packages/cb-cookie-banner/src/constants.ts +++ b/packages/cb-cookie-banner/src/constants.ts @@ -1 +1,4 @@ export const TRANSITION_TIME_MS = 100; +const PREFERENCE_EXPIRATION_YEAR = 1; +export const EXPIRATION_DAYS = PREFERENCE_EXPIRATION_YEAR * 365; +export const ADVERTISING_SHARING_ALLOWED = 'advertising_sharing_allowed'; diff --git a/packages/cb-cookie-manager/src/index.ts b/packages/cb-cookie-manager/src/index.ts index c58927d..5af034e 100644 --- a/packages/cb-cookie-manager/src/index.ts +++ b/packages/cb-cookie-manager/src/index.ts @@ -13,6 +13,7 @@ export { useTrackingManager } from './TrackingManagerContext'; export { Framework, Region, TrackerType, TrackingCategory, TrackingPreference } from './types'; export { default as areCookiesEnabled } from './utils/areCookiesEnabled'; export { default as getDefaultTrackingPreference } from './utils/getDefaultTrackingPreference'; +export { getDomainWithoutSubdomain } from './utils/getDomain'; export { default as isOptOut } from './utils/isOptOut'; export { getIsMobileAppFromQueryParams,