Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Aug 24, 2023
1 parent f418e04 commit 38b2a5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
37 changes: 22 additions & 15 deletions packages/consent/consent-wrapper-onetrust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,28 @@ withOneTrust(analytics).load({ writeKey: '<MY_WRITE_KEY'> })

```

## For snippet users (window.analytics) who _also_ use a bundler like webpack
## For snippet users (window.analytics)

### _NOTE:_ a pre-bundled version that can be loaded through a `<script>` is on the roadmap, but _not_ supported at this point

- Install the dependency (see directions)
- Delete the `analytics.load()` line from the snippet

```diff
- analytics.load("<MY_WRITE_KEY>");
```html
<!-- Add OneTrust Script -->
<script
src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"
type="text/javascript"
charset="UTF-8"
data-domain-script="YOUR-DOMAIN-SCRIPT-ID"
></script>

<!-- Add Segment Analytics Script -->
<script>
!function(){var analytics=window.analytics...
<!-- Delete the `analytics.load()` line from the snippet! -->
</script>
<!-- Add Segment Consent Wrapper Script -->
<script src="https://unpkg.com/@segment/analytics-consent-wrapper-onetrust/dist/umd/standalone.js"></script>
<script>
withOneTrust(analytics).load('<YOUR_WRITEKEY>')
</script>
```
- Use the following initialization code

```ts
import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust'

withOneTrust(window.analytics).load('<WRITE_KEY>')
```
#### Reminder: _delete_ `analytics.load('....')` from the original Segment snippet so that only .load() is only called after `withOneTrust` is called. See comment in example above.
Original file line number Diff line number Diff line change
@@ -1,28 +1,2 @@
import { withOneTrust } from '../index'

/**
* usage:
* ```html
* <!-- Add OneTrust Script -->
* <script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" type="text/javascript" charset="UTF-8" data-domain-script="YOUR-DOMAIN-SCRIPT-ID"></script>
*
* <!-- Add Segment Analytics Script -->
* <script>
* !function(){var analytics=window.analytics=window.analytics||[]...
* <!-- Delete analytics.load -->
* </script>
*
* <!-- Add Segment Consent Wrapper Script -->
* <script src="https://unpkg.com/@segment/analytics-consent-wrapper-onetrust/dist/umd/standalone.js"></script>
*
* ```
*/

// If we ever need to support an analytics instance that is renamed something else, we can add support for a custom attribute to the script tag.
if ((window as any).analytics) {
withOneTrust((window as any).analytics)
} else {
console.error(
'Will not load OneTrust wrapper. window.analytics is not defined'
)
}
;(window as any).withOneTrust = withOneTrust

0 comments on commit 38b2a5c

Please sign in to comment.