Skip to content

feat(segment): bring back segment and block specific user agents#5944

Open
fabianrbz wants to merge 1 commit into
mainfrom
feat/segment-skip-user-agents
Open

feat(segment): bring back segment and block specific user agents#5944
fabianrbz wants to merge 1 commit into
mainfrom
feat/segment-skip-user-agents

Conversation

@fabianrbz

Copy link
Copy Markdown
Contributor

Description

Add segment and block specific user agents.

Preview Links

Checklist

  • Tested how-to docs. If not, note why here.
  • All pages contain metadata.
  • Any new docs link to existing docs.
  • All autogenerated instructions render correctly (API, decK, Konnect, Kong Manager).
  • Style guide (capitalized gateway entities, placeholder URLs) implemented correctly.
  • Every page has a description entry in frontmatter.
  • Add new pages to the product documentation index (if applicable).

@fabianrbz fabianrbz requested a review from a team as a code owner July 14, 2026 12:23
Copilot AI review requested due to automatic review settings July 14, 2026 12:23
@netlify

netlify Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploy Preview for kongdeveloper ready!

Name Link
🔨 Latest commit da2fa28
🔍 Latest deploy log https://app.netlify.com/projects/kongdeveloper/deploys/6a562a4d3b0cdd0008e958cc
😎 Deploy Preview https://deploy-preview-5944--kongdeveloper.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Reintroduces Segment analytics on the default layout while adding a UA-based bot filter, with the blocked UA list managed via site data during the Jekyll build.

Changes:

  • Load a blocked_user_agents YAML file into site.data during site generation.
  • Add Segment snippet back to default.html, skipping zh-CN locales and blocking known bot/user-agent patterns.
  • Introduce a YAML config file containing exact and substring UA patterns to exclude from tracking.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
app/_plugins/generators/site_data.rb Loads blocked UA config into site.data during site generation.
app/_layouts/default.html Re-adds Segment snippet with locale gating and UA bot filtering.
app/_config/blocked_user_agents.yml Defines exact/substr UA patterns to block from Segment tracking.

Comment on lines +52 to +54
def load_blocked_user_agents(site)
site.data['blocked_user_agents'] = YAML.load_file(File.expand_path('app/_config/blocked_user_agents.yml'))
end
Comment thread app/_layouts/default.html
Comment on lines +88 to +89
{% if jekyll.environment == "production" and page.url != '/search/' and page.url != '/support/' %}
<!-- Disable Segment on /search/ for now -->
Comment thread app/_layouts/default.html
if (!_isBot) {
!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="SMHOU8AoTR3Ekuuu4A9MkIOv6fmGfbkq";;analytics.SNIPPET_VERSION="5.2.0";
analytics.load("SMHOU8AoTR3Ekuuu4A9MkIOv6fmGfbkq");
analytics.page({{category}}, '{{page.title | liquify}}', {}, getSegmentConsentContext());
Comment thread app/_layouts/default.html
var _botUaExact = new Set({{ site.data.blocked_user_agents.exact | jsonify }});
var _botUaContains = {{ site.data.blocked_user_agents.substrings | jsonify }};
var _ua = navigator.userAgent;
var _isBot = _botUaExact.has(_ua) || _botUaContains.some(function(p) { return _ua.toLowerCase().indexOf(p) !== -1; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants