segmentio / consent-manager

Drop-in consent management plugin for analytics.js
https://segmentio.github.io/consent-manager/
MIT License
341 stars 144 forks source link

Error with addSourceMiddleware #168

Closed Lewitje closed 3 years ago

Lewitje commented 3 years ago

I get the error: TypeError: Cannot read properties of undefined (reading 'addSourceMiddleware')

image

image

Fernan-Ramos commented 3 years ago

I have the same problem, I have try to change the version from but the problem persists, any idea? Thanks!

felipe-najson-ntf commented 3 years ago

Hi @Lewitje @Fernan-Ramos, could I get more information about how you are using it?

For instance

Thanks, segment team.

Fernan-Ramos commented 3 years ago

Hi I’m using the 5.1.0 version and the implementation is Consent Manager on react js. Instead I try to use the 5.2.0 and the 5.3.0 version but the error persists. On incognito mode the error not appear, could be related with the cookies or something similar? Thanks

Lewitje commented 3 years ago

I'm using:

Not sure if this is related but window.consentManager.openConsentManager() doesn't work after the user has saved their cookie preferences, only before.

pooyaj commented 3 years ago

Hey @Lewitje @Fernan-Ramos, could you please check the version of your Segment Snippet? I'm suspecting you are using an outdated snippet, and therefore, the addSourceMiddleware method is unavailable (https://github.com/segmentio/consent-manager/blob/master/README.md?plain=1#L86-L108)

felipe-najson-ntf commented 3 years ago

Hi @Lewitje @Fernan-Ramos I agree with @pooyaj. Try adding the last version of Segment snippet documented here. https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2-copy-the-segment-snippet and follow the instructions on the readme file of Consent Manager.

Segment Team.

Lewitje commented 3 years ago

I'm still getting the error, in google tag manager I have this snippet (with my write key replaced by the 'x'):

<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="x";analytics.SNIPPET_VERSION="4.13.2"; analytics.page(); }}(); </script>

felipe-najson-ntf commented 3 years ago

Hi @Lewitje, sorry for the late reply, your mistake is that you are adding the segment key in the code snippet and it should go in the script where you configure the consent manager.

Try again by removing the line analytics._writeKey = "x"; And adding your key in the component configuration as seen here. image

Once this is done you can add the container to position your banner wherever you want.

Example:

Screen Shot 2021-10-18 at 08 52 52

I hope you find it useful. Regards, segment team