Comments (5)
This is still affecting us, any chance of a fix?
from analytics-next.
Is there any reason not to use globalThis
?
Since this is meant to be imported into an app, let the app decide the polyfilling and whatnot.
from analytics-next.
Fixed in #502
from analytics-next.
Here's a patch package for anyone that's blocked by this:
diff --git a/node_modules/@segment/analytics-next/dist/pkg/analytics.js b/node_modules/@segment/analytics-next/dist/pkg/analytics.js
index 80f0914..790c2bd 100644
--- a/node_modules/@segment/analytics-next/dist/pkg/analytics.js
+++ b/node_modules/@segment/analytics-next/dist/pkg/analytics.js
@@ -13,7 +13,7 @@ import { PersistedPriorityQueue } from './lib/priority-queue/persisted';
var deprecationWarning = 'This is being deprecated and will be not be available in future releases of Analytics JS';
// reference any pre-existing "analytics" object so a user can restore the reference
// eslint-disable-next-line @typescript-eslint/no-explicit-any
-var globalAny = global;
+var globalAny = {};
var _analytics = globalAny.analytics;
var Analytics = /** @class */ (function (_super) {
__extends(Analytics, _super);
diff --git a/node_modules/@segment/analytics-next/dist/pkg/lib/load-script.js b/node_modules/@segment/analytics-next/dist/pkg/lib/load-script.js
index 43e22d7..de9e70a 100644
--- a/node_modules/@segment/analytics-next/dist/pkg/lib/load-script.js
+++ b/node_modules/@segment/analytics-next/dist/pkg/lib/load-script.js
@@ -18,7 +18,7 @@ export function loadScript(src, attributes) {
}
return new Promise(function (resolve, reject) {
var _a;
- var script = global.window.document.createElement('script');
+ var script = window.document.createElement('script');
script.type = 'text/javascript';
script.src = src;
script.async = true;
@@ -37,7 +37,7 @@ export function loadScript(src, attributes) {
script.setAttribute('status', 'error');
reject(new Error("Failed to load " + src));
};
- var tag = global.window.document.getElementsByTagName('script')[0];
+ var tag = window.document.getElementsByTagName('script')[0];
(_a = tag.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(script, tag);
});
}
diff --git a/node_modules/@segment/analytics-next/dist/pkg/plugins/ajs-destination/loader.js b/node_modules/@segment/analytics-next/dist/pkg/plugins/ajs-destination/loader.js
index c280cf1..096e61d 100644
--- a/node_modules/@segment/analytics-next/dist/pkg/plugins/ajs-destination/loader.js
+++ b/node_modules/@segment/analytics-next/dist/pkg/plugins/ajs-destination/loader.js
@@ -10,7 +10,7 @@ function normalizeName(name) {
function recordLoadMetrics(fullPath, ctx, name) {
var _a, _b, _c;
try {
- var metric = ((_c = (_b = (_a = global.window) === null || _a === void 0 ? void 0 : _a.performance) === null || _b === void 0 ? void 0 : _b.getEntriesByName(fullPath, 'resource')) !== null && _c !== void 0 ? _c : [])[0];
+ var metric = ((_c = (_b = (_a = window) === null || _a === void 0 ? void 0 : _a.performance) === null || _b === void 0 ? void 0 : _b.getEntriesByName(fullPath, 'resource')) !== null && _c !== void 0 ? _c : [])[0];
// we assume everything that took under 100ms is cached
metric &&
ctx.stats.gauge('legacy_destination_time', Math.round(metric.duration), __spreadArrays([
diff --git a/node_modules/@segment/analytics-next/src/__tests__/csp-detection.test.ts b/node_modules/@segment/analytics-next/src/__tests__/csp-detection.test.ts
deleted file mode 100644
index 283d6a1..0000000
from analytics-next.
Seconding the above. It's a pain when using in NextJS
from analytics-next.
Related Issues (20)
- Provide visibility to errors if segment events do not send
- Rename @segment/analytics-node to @segment/analytics-javascript HOT 3
- Rare Context2 in Nuxt 3 HOT 1
- Can not install library without node overrides HOT 5
- Consent module pollutes logs when using OneTrust's "Consent Rate Optimization" feature. HOT 1
- Can `.load()` support a symmetric key to not expose real write key? HOT 1
- analytics-node does not close HTTPS connection on closeAndFlush HOT 2
- Snippet version 5.2.0 loads analytics.min.js and analytics.classic.js at the same time HOT 1
- How to Set a Whitelist of Domains for a Segment JavaScript source WriteKey to Prevent Misuse? HOT 1
- Typescript issue on consent object of CoreExtraContext type HOT 1
- Analytics not flushed in Node >= 18 HOT 1
- Safari's Enhanced Tracking Protection Leads to Unhandled Promise Rejection HOT 11
- @segment/analytics-consent-wrapper-onetrust README code sandbox link looks incorrect HOT 1
- npm install fails for Node 18.XX and Node 20.XX HOT 1
- Cannot install package via NPM HOT 7
- Could not resolve "./lib/window-analytics-helper" when building with vite HOT 1
- Setting a low `flushInterval` effectively breaks `closeAndFlush()` HOT 2
- analytics.user function should be listed as optionally undefined in typescript definitions
- Serve polyfill bundle from segment.com domain (for snippet/standalone users) HOT 6
- How to write an enrichment plugin that fires after a remote integration? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from analytics-next.