Skip to content

Commit

Permalink
feat(ConsentManager): Enable onLoad functionality for scripts (#981)
Browse files Browse the repository at this point in the history
🎟️ [Asana Task](https://app.asana.com/0/1202791227659279/1204854420026344/f)
πŸ” [Preview Link](https://react-components-git-nels-update-consent-manager-hashicorp.vercel.app/components/consentmanager)

## Description
This change enables `onLoad` functionality for scripts loaded via the `ConsentManager` component. This will allow us to register an event handler to track events for the Qualified chatbot.

## Validation Steps
- [ ] Navigate to [the preview](https://react-components-git-nels-update-consent-manager-hashicorp.vercel.app/components/consentmanager)
- [ ] Validate that there are no errors in the console
- [ ] Navigate to the [preview of the canary release on `www`](https://hashicorp-www-next-git-nels-observabilityadd-t-1713ef-hashicorp.vercel.app/)
- [ ] Validate that the `qualified.js` script loads in the DOM
<img width="451" alt="Screenshot 2023-07-12 at 9 33 53 AM" src="https://github.com/hashicorp/react-components/assets/39201593/19dda5de-c788-41f8-88ce-e3de62b88103">
  • Loading branch information
nandereck committed Jul 14, 2023
1 parent db3dfbf commit 0aedf44
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-pianos-draw.md
@@ -0,0 +1,5 @@
---
'@hashicorp/react-consent-manager': minor
---

Add onload functionality to scripts handled by ConsentManager
1 change: 1 addition & 0 deletions packages/consent-manager/scripts/custom.tsx
Expand Up @@ -31,6 +31,7 @@ function CustomScript({ service }: CustomScriptProps) {
strategy={strategy}
id={service.name}
{...dataAttrs}
onLoad={service?.onLoad}
>
{service.body ? service.body : null}
</Script>
Expand Down
6 changes: 6 additions & 0 deletions packages/consent-manager/types.ts
Expand Up @@ -19,6 +19,12 @@ export interface ConsentManagerService {
* If left undefined, script will load as usual.
*/
shouldLoad?: () => boolean
/**
* Optional function that runs when a script has
* finished loading.
* Docs: https://nextjs.org/docs/pages/api-reference/components/script#onload
*/
onLoad?: () => void
}

export interface ConsentManagerPreset {
Expand Down

1 comment on commit 0aedf44

@vercel
Copy link

@vercel vercel bot commented on 0aedf44 Jul 14, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

react-components – ./

react-components-git-main-hashicorp.vercel.app
react-components.vercel.app
react-components-hashicorp.vercel.app

Please sign in to comment.