-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add umd build script and other changes
Update heavy-boxes-grab.md
- Loading branch information
Showing
20 changed files
with
771 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@segment/analytics-consent-wrapper-onetrust': minor | ||
--- | ||
|
||
Change API from oneTrust(analytics) -> withOneTrust(analytics). Allow withOneTrust(analytics).load(...). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@segment/analytics-consent-tools': patch | ||
--- | ||
|
||
Have `createWrapper` return analytics instance to allow `.load` to be chained. |
160 changes: 160 additions & 0 deletions
160
examples/standalone-playground/pages/index-consent.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<html> | ||
|
||
<head> | ||
<style> | ||
body { | ||
font-family: monospace; | ||
} | ||
|
||
#event { | ||
margin: 2em 0; | ||
min-height: 200px; | ||
min-width: 700px; | ||
} | ||
</style> | ||
|
||
<form method="get"> | ||
<input type="text" name="writeKey" placeholder="Writekey" /> | ||
<button>Load</button> | ||
</form> | ||
|
||
<script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" type="text/javascript" | ||
data-domain-script="80ca7b5c-e72f-4bd0-972a-b74d052a0820-test"></script> | ||
<script> | ||
const { searchParams } = new URL(document.location); | ||
const writeKey = searchParams.get("writeKey"); | ||
document.querySelector("input").value = writeKey; | ||
|
||
if (writeKey) { | ||
!(function () { | ||
var analytics = (window.analytics = window.analytics || []) | ||
if (!analytics.initialize) | ||
if (analytics.invoked) | ||
window.console && | ||
console.error && | ||
console.error('Segment snippet included twice.') | ||
else { | ||
analytics.invoked = !0 | ||
analytics.methods = [ | ||
'screen', | ||
'register', | ||
'deregister', | ||
'trackSubmit', | ||
'trackClick', | ||
'trackLink', | ||
'trackForm', | ||
'pageview', | ||
'identify', | ||
'reset', | ||
'group', | ||
'track', | ||
'ready', | ||
'alias', | ||
'debug', | ||
'page', | ||
'once', | ||
'off', | ||
'on', | ||
'addSourceMiddleware', | ||
'addIntegrationMiddleware', | ||
'setAnonymousId', | ||
'addDestinationMiddleware', | ||
] | ||
analytics.factory = function (e) { | ||
return function () { | ||
var t = Array.prototype.slice.call(arguments) | ||
t.unshift(e) | ||
analytics.push(t) | ||
return analytics | ||
} | ||
} | ||
for (var e = 0; e < analytics.methods.length; e++) { | ||
var key = analytics.methods[e] | ||
analytics[key] = analytics.factory(key) | ||
} | ||
analytics.load = function (key, e) { | ||
var t = document.createElement('script') | ||
t.type = 'text/javascript' | ||
t.async = !0 | ||
t.src = | ||
'https://cdn.segment.com/analytics.js/v1/' + | ||
writeKey + | ||
'/analytics.min.js' | ||
var n = document.getElementsByTagName('script')[0] | ||
n.parentNode.insertBefore(t, n) | ||
analytics._loadOptions = e | ||
} | ||
analytics.SNIPPET_VERSION = '4.13.1' | ||
analytics._writeKey = writeKey | ||
analytics.page() | ||
} | ||
})() | ||
} | ||
</script> | ||
<script data-segment-ot-autoload src="http://localhost:9000/standalone.js"></script> | ||
</head> | ||
|
||
<body> | ||
<form> | ||
<textarea name="event" id="event"> | ||
{ | ||
"name": "hi", | ||
"properties": { }, | ||
"traits": { }, | ||
"options": { } | ||
} | ||
</textarea> | ||
<div> | ||
<button id="track">Track</button> | ||
<button id="identify">Identify</button> | ||
</div> | ||
</form> | ||
|
||
<pre id="logs"></pre> | ||
|
||
<script type="text/javascript"> | ||
document.querySelector('#track').addEventListener('click', async (e) => { | ||
e.preventDefault() | ||
const contents = document.querySelector('#event').value | ||
const evt = JSON.parse(contents) | ||
const promise = window.analytics.track( | ||
evt.name ?? '', | ||
evt.properties ?? {}, | ||
evt.options ?? {} | ||
) | ||
|
||
promise?.then((ctx) => { | ||
ctx.flush() | ||
document.querySelector('#logs').textContent = JSON.stringify( | ||
ctx.event, | ||
null, | ||
' ' | ||
) | ||
}) | ||
}) | ||
|
||
document | ||
.querySelector('#identify') | ||
.addEventListener('click', async (e) => { | ||
e.preventDefault() | ||
const contents = document.querySelector('#event').value | ||
const evt = JSON.parse(contents) | ||
const promise = window.analytics.identify( | ||
evt.name ?? '', | ||
evt.properties ?? {}, | ||
evt.options ?? {} | ||
) | ||
|
||
promise?.then((ctx) => { | ||
ctx.flush() | ||
document.querySelector('#logs').textContent = JSON.stringify( | ||
ctx.event, | ||
null, | ||
' ' | ||
) | ||
}) | ||
}) | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @internal/config-webpack | ||
|
||
This package is for sharing basic webpack configuration / browser support between all of the analytics.js artifacts in this monorepo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@internal/config-webpack", | ||
"version": "0.0.0", | ||
"private": true, | ||
"packageManager": "yarn@3.4.1", | ||
"devDependencies": { | ||
"@types/circular-dependency-plugin": "^5", | ||
"circular-dependency-plugin": "^5.2.2", | ||
"terser-webpack-plugin": "^5.1.4", | ||
"ts-loader": "^9.1.1", | ||
"webpack": "^5.76.0", | ||
"webpack-cli": "^4.8.0", | ||
"webpack-merge": "^5.9.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const TerserPlugin = require('terser-webpack-plugin') | ||
const CircularDependencyPlugin = require('circular-dependency-plugin') | ||
|
||
const isProd = process.env.NODE_ENV === 'production' | ||
const isWatch = process.env.WATCH === 'true' | ||
|
||
/** | ||
* This is a base webpack config that is used for all generic web packages. | ||
* It should contain the same support as analytics.js (e.g. es5, minified, etc) | ||
* | ||
* | ||
* @type { import('webpack').Configuration } | ||
*/ | ||
module.exports = { | ||
devtool: 'source-map', | ||
stats: isWatch ? 'errors-warnings' : 'normal', | ||
mode: isProd ? 'production' : 'development', | ||
target: ['web', 'es5'], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.tsx?$/, | ||
use: [ | ||
{ | ||
loader: 'ts-loader', | ||
options: { | ||
configFile: 'tsconfig.json', | ||
transpileOnly: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
optimization: { | ||
moduleIds: 'deterministic', | ||
minimize: isProd, | ||
minimizer: [ | ||
new TerserPlugin({ | ||
extractComments: false, | ||
terserOptions: { | ||
ecma: '2015', | ||
mangle: true, | ||
compress: true, | ||
output: { | ||
comments: false, | ||
}, | ||
}, | ||
}), | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
plugins: [ | ||
new CircularDependencyPlugin({ | ||
failOnError: true, | ||
}), | ||
], | ||
} |
8 changes: 3 additions & 5 deletions
8
packages/consent/consent-tools-integration-tests/src/page-bundles/onetrust/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { AnalyticsBrowser } from '@segment/analytics-next' | ||
import { oneTrust } from '@segment/analytics-consent-wrapper-onetrust' | ||
import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust' | ||
|
||
export const analytics = new AnalyticsBrowser() | ||
|
||
oneTrust(analytics, { | ||
withOneTrust(analytics, { | ||
disableConsentChangedEvent: false, | ||
integrationCategoryMappings: { | ||
Fullstory: ['C0001'], | ||
'Actions Amplitude': ['C0004'], | ||
}, | ||
}) | ||
}).load({ writeKey: '9lSrez3BlfLAJ7NOChrqWtILiATiycoc' }) | ||
;(window as any).analytics = analytics | ||
|
||
analytics.load({ writeKey: '9lSrez3BlfLAJ7NOChrqWtILiATiycoc' }) | ||
void window.analytics.page().then(console.log) |
4 changes: 2 additions & 2 deletions
4
packages/consent/consent-tools-integration-tests/src/page-bundles/snippet/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.