Skip to content

Conversation

katzino
Copy link
Contributor

@katzino katzino commented Jul 11, 2025

  • fixes analytics script to be correctly loaded using withOneTrust
  • adds header button click tracking

@katzino katzino added this to the 118th sprint - Web Team milestone Jul 11, 2025
@katzino katzino requested review from HonzaTuron and jbartadev July 11, 2025 11:04
@katzino katzino self-assigned this Jul 11, 2025
@katzino katzino added bug Something isn't working. adhoc Ad-hoc unplanned task added during the sprint. t-web Issues with this label are in the ownership of the web team. labels Jul 11, 2025
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: OneTrust Integration Broken by Incorrect Analytics Loading Order

The order of operations for withOneTrust and analytics.load was reversed. analytics.load() is now called first, passing its undefined return value to withOneTrust instead of the analytics object. This breaks the OneTrust consent management integration with Segment analytics. The correct pattern is withOneTrust(analytics).load(...).

src/plugins/docusaurus-plugin-segment/index.js#L51-L52

!function(){var i="analytics",analytics=window[i]=window[i]||[];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","screen","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware","register"];analytics.factory=function(e){return function(){if(window[i].initialized)return window[i][e].apply(window[i],arguments);var n=Array.prototype.slice.call(arguments);if(["track","screen","alias","group","page","identify"].indexOf(e)>-1){var c=document.querySelector("link[rel='canonical']");n.push({__t:"bpc",c:c&&c.getAttribute("href")||void 0,p:location.pathname,u:location.href,s:location.search,t:document.title,r:document.referrer})}n.unshift(e);analytics.push(n);return analytics}};for(var n=0;n<analytics.methods.length;n++){var key=analytics.methods[n];analytics[key]=analytics.factory(key)}analytics.load=function(key,n){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.setAttribute("data-global-segment-analytics-key",i);t.src="https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(t,r);analytics._loadOptions=n};analytics._writeKey="${writeKey}";;analytics.SNIPPET_VERSION="5.2.0";
withOneTrust(analytics.load("${writeKey}", { integrations: { "Segment.io": { apiHost: "analytics.apify.com/v1" } } }));

Fix in CursorFix in Web


Comment bugbot run to trigger another review on this PR
Was this report helpful? Give feedback by reacting with 👍 or 👎

@apify-service-account
Copy link

Preview for this PR was built for commit 8fca669 and is ready at https://pr-1684.preview.docs.apify.com!

@katzino katzino merged commit 92aa96d into master Jul 11, 2025
10 checks passed
@katzino katzino deleted the fix/analytics-tracking branch July 11, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adhoc Ad-hoc unplanned task added during the sprint. bug Something isn't working. t-web Issues with this label are in the ownership of the web team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants