Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Cannot read properties of undefined (reading addSourceMiddleware) when Incognito (Google Chrome) #334

Open
aceykt opened this issue Jun 2, 2023 · 1 comment

Comments

@aceykt
Copy link

aceykt commented Jun 2, 2023

Repository to simulate: https://github.com/seg-leonelsanches/leos-guitar-shop-nextjs
Consent Manager version: 5.8.1
Analytics.js version: 1.52.0
Node.js version: 18.16.0

Use yarn dev to initialize the project locally. If open within a Chrome regular tab, it works normally. If open with Incognito, the following is shown:

image

I debugged the sources and it seems that, in analytics.js file from Consent Manager ESM, we don't have wd.analytics set properly.

@edsonjab
Copy link
Contributor

edsonjab commented Jun 5, 2023

Hi @aceykt you need add this code on the <head>element:

```<script>
  !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=["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/" + key + "/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics._writeKey="YOUR_KEY";;analytics.SNIPPET_VERSION="4.15.3";
  analytics.load("YOUR_KEY");
  analytics.page();
  }}();
</script>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants