Skip to content

Commit

Permalink
Better segment (#1691)
Browse files Browse the repository at this point in the history
* Set userId and groupId

* trim

* Attempt to delete bad cookies

* No API key needed for diffing or branch builds
  • Loading branch information
gj authored Apr 1, 2023
1 parent a009e63 commit 741e1d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/docs-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ jobs:
hugo-version: '0.79.1'
if: steps.cache.outputs.cache-hit != 'true'
- name: Build Hugo docs
env:
HUGO_SEGMENT_API_KEY: ""
run: make build
if: steps.cache.outputs.cache-hit != 'true'
working-directory: docs
Expand Down Expand Up @@ -172,6 +174,8 @@ jobs:
hugo-version: '0.79.1'
if: steps.cache.outputs.cache-hit != 'true'
- name: Build Hugo docs
env:
HUGO_SEGMENT_API_KEY: ""
run: make build
working-directory: docs
if: steps.cache.outputs.cache-hit != 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
# Try to retry, and get some more info about why the flake is happening.
- name: Build docs for CI preview
env:
HUGO_SEGMENT_API_KEY: ${{ secrets.SEGMENT_API_KEY_DEV }}
HUGO_SEGMENT_API_KEY: ""
uses: nick-invision/retry@v2
with:
max_attempts: 2
Expand Down
31 changes: 28 additions & 3 deletions docs/themes/oso-tailwind/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,34 @@
</script>
<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="{{ os.Getenv "HUGO_SEGMENT_API_KEY" }}";analytics.SNIPPET_VERSION="4.15.2";
analytics.load("{{ os.Getenv "HUGO_SEGMENT_API_KEY" }}");
analytics.page();
analytics.load("{{ os.Getenv "HUGO_SEGMENT_API_KEY" }}");

var userId;
var groupId;

try {
// Turn `"a=b; c=d"` into `{a: b, c: d}`
var cookies = document.cookie.split('; ').reduce(function(cookies, cookie) {
var c = cookie.trim().split('=');
return { ...cookies, [c[0]]: c[1] };
}, {});

userId = cookies['ajs_user_id'];
groupId = cookies['ajs_group_id'];
} catch (e) {}

// Attempt to delete cookies where the userId is a tenant ID.
if (userId.slice(0, 2) === 't_') {
document.cookie = 'ajs_user_id=' + userId + '; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=.osohq.com';
userId = undefined;
}

analytics.page(
"Library Docs",
undefined,
{ tenantId: groupId },
{ context: { app: { name: "library-docs" }, groupId }, userId },
);
}}();
</script>

</head>

1 comment on commit 741e1d7

@github-actions
Copy link

Choose a reason for hiding this comment

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

Rust Benchmark

Benchmark suite Current: 741e1d7 Previous: a009e63 Ratio
rust_get_attribute 50395 ns/iter (± 2673) 42240 ns/iter (± 1246) 1.19
n_plus_one/100 2461237 ns/iter (± 87516) 2267916 ns/iter (± 25370) 1.09
n_plus_one/500 11897477 ns/iter (± 498473) 11003216 ns/iter (± 47510) 1.08
n_plus_one/1000 23884539 ns/iter (± 675485) 21871146 ns/iter (± 95978) 1.09
unify_once 1026 ns/iter (± 187) 873 ns/iter (± 548) 1.18
unify_twice 2911 ns/iter (± 131) 2548 ns/iter (± 38) 1.14
many_rules 66226 ns/iter (± 2893) 61041 ns/iter (± 1159) 1.08
fib/5 596909 ns/iter (± 20247) 530332 ns/iter (± 17509) 1.13
prime/3 21081 ns/iter (± 832) 17853 ns/iter (± 539) 1.18
prime/23 20698 ns/iter (± 1240) 17808 ns/iter (± 1516) 1.16
prime/43 20717 ns/iter (± 930) 17808 ns/iter (± 532) 1.16
prime/83 21283 ns/iter (± 1145) 17830 ns/iter (± 644) 1.19
prime/255 18953 ns/iter (± 945) 16094 ns/iter (± 484) 1.18
indexed/100 6435 ns/iter (± 811) 5443 ns/iter (± 567) 1.18
indexed/500 7985 ns/iter (± 2375) 6133 ns/iter (± 1390) 1.30
indexed/1000 9691 ns/iter (± 651) 7484 ns/iter (± 204) 1.29
indexed/10000 26277 ns/iter (± 3795) 18124 ns/iter (± 1727) 1.45
not 6438 ns/iter (± 264) 5727 ns/iter (± 405) 1.12
double_not 13538 ns/iter (± 500) 12068 ns/iter (± 149) 1.12
De_Morgan_not 8688 ns/iter (± 391) 7687 ns/iter (± 222) 1.13
load_policy 1054168 ns/iter (± 37089) 931784 ns/iter (± 3662) 1.13
partial_and/1 34927 ns/iter (± 2009) 30629 ns/iter (± 981) 1.14
partial_and/5 125399 ns/iter (± 5839) 105237 ns/iter (± 3976) 1.19
partial_and/10 247876 ns/iter (± 6712) 200122 ns/iter (± 4657) 1.24
partial_and/20 509524 ns/iter (± 8321) 416894 ns/iter (± 6764) 1.22
partial_and/40 1076171 ns/iter (± 34981) 916503 ns/iter (± 9202) 1.17
partial_and/80 2432455 ns/iter (± 60133) 2101727 ns/iter (± 4779) 1.16
partial_and/100 3189041 ns/iter (± 83236) 2791443 ns/iter (± 7444) 1.14
partial_rule_depth/1 114350 ns/iter (± 7305) 95094 ns/iter (± 3431) 1.20
partial_rule_depth/5 388024 ns/iter (± 16117) 323562 ns/iter (± 8084) 1.20
partial_rule_depth/10 819591 ns/iter (± 29724) 724867 ns/iter (± 17321) 1.13
partial_rule_depth/20 2339332 ns/iter (± 75575) 2047494 ns/iter (± 8835) 1.14
partial_rule_depth/40 8451329 ns/iter (± 252473) 7274026 ns/iter (± 50202) 1.16
partial_rule_depth/80 47308666 ns/iter (± 1681664) 37059908 ns/iter (± 386646) 1.28
partial_rule_depth/100 88069562 ns/iter (± 2342398) 68400463 ns/iter (± 509355) 1.29

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.