Skip to content

Commit

Permalink
Merge pull request #37 from rasummer/rasummer/add-pendo-back
Browse files Browse the repository at this point in the history
add pendo back
  • Loading branch information
beritou authored Dec 10, 2024
2 parents 150bff3 + dc8956c commit 74aa372
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/supplemental_ui/js/vendor/js.cookie.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 77 additions & 1 deletion docs/supplemental_ui/partials/footer-scripts-supplemental.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
{{!-- add supplemental scripts as needed --}}
<script src="{{uiRootPath}}/js/vendor/js.cookie.min.js" ></script>
<script type="text/plain" class="optanon-category-3">
(function(apiKey){
(function(p,e,n,d,o){var v,w,x,y,z;o=p[d]=p[d]||{};o._q=o._q||[];
v=['initialize','identify','updateOptions','pageLoad','track'];for(w=0,x=v.length;w<x;++w)(function(m){
o[m]=o[m]||function(){o._q[m===v[0]?'unshift':'push']([m].concat([].slice.call(arguments,0)));};})(v[w]);
y=e.createElement(n);y.async=!0;y.src='https://content.pa.lightbend.com/agent/static/'+apiKey+'/pendo.js';
z=e.getElementsByTagName(n)[0];z.parentNode.insertBefore(y,z);})(window,document,'script','pendo');
const getEnv = () => {
const { hostname } = window.location;
switch (hostname) {
case "localhost":
return "localhost";
case "doc.akka.io":
return "prod";
default:
if (hostname.includes("akka.work")) {
return "workbench";
}
return "unknown";
}
};
// NOTE: doc https://support.pendo.io/hc/en-us/articles/360037760572-Tracking-Anonymous-Visitors-Across-Subdomains
const getCookieDomain = () => {
const { hostname } = window.location;
switch (hostname) {
case "localhost":
return "localhost";
case "doc.akka.io":
return ".akka.io";
default:
if (hostname.includes("akka.work")) {
return ".akka.work";
}
return "unknown";
}
};
const saveCookie = (userId) => {
Cookies.set('_track_pv', userId.replace("users/", ""), { domain: getCookieDomain(), expires: 35 });
};
// read userId from cookie
const userId = Cookies.get('_track_pv');
if (userId && userId !== "undefined") {
pendo.initialize({
visitor: {
id: userId.startsWith("_PENDO_T_") ? userId : "users/" + userId,
environment: getEnv()
},
cookieDomain: getCookieDomain()
});
// save cookie to update cookie expiration date
saveCookie(userId);
} else {
pendo.initialize({
visitor: {
environment: getEnv()
},
cookieDomain: getCookieDomain()
});
// save visitorId to cookie
setTimeout(() => {
const visitorId = pendo.visitorId
if (visitorId) {
saveCookie(visitorId);
}
}, 1000);
}
})('244586c2-5138-4af9-6ec1-a39cdd9d974d');
</script>

0 comments on commit 74aa372

Please sign in to comment.