Skip to content

Commit

Permalink
feat(consent-manager): Add shouldLoad to custom services (#951)
Browse files Browse the repository at this point in the history
* Add custom scripts wrapper component

* Create fuzzy-pandas-fly.md

* add hide to service

* chore: delete unused component and update type name

* chore: update comment

* Update .changeset/fuzzy-pandas-fly.md

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>

---------

Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
  • Loading branch information
pbortnick and Bryce Kalow committed May 3, 2023
1 parent 32cf8a0 commit cb32ea4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-pandas-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hashicorp/react-consent-manager": minor
---

feat(consent-manager): Add custom scripts wrapper component
4 changes: 4 additions & 0 deletions packages/consent-manager/scripts/custom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ function CustomScript({ service }: CustomScriptProps) {
const strategy =
service.strategy ?? service.async ? 'afterInteractive' : 'beforeInteractive'

if (service.shouldLoad !== undefined && !service.shouldLoad()) {
return null
}

return (
<Script
src={service.url}
Expand Down
6 changes: 6 additions & 0 deletions packages/consent-manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export interface ConsentManagerService {
name: string
url?: string
dataAttrs?: { name: string; value: string }[]
/**
* Optional function that determines whether
* or not the script will load on the page.
* If left undefined, script will load as usual.
*/
shouldLoad?: () => boolean
}

export interface ConsentManagerPreset {
Expand Down

1 comment on commit cb32ea4

@vercel
Copy link

@vercel vercel bot commented on cb32ea4 May 3, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.