Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<%= stylesheet_pack_tag 'application', media: 'all' %>
<%= render 'shared/posthog' if ENV['POSTHOG_TOKEN'] %>
<%= render 'shared/plausible' if !signed_in? && ENV['PLAUSIBLE_DOMAIN'] %>
<%= render 'shared/pendo' if ENV['PENDO_API_KEY'] %>
</head>
<body>
<turbo-frame id="modal"></turbo-frame>
Expand Down
17 changes: 17 additions & 0 deletions app/views/shared/_pendo.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
(function(apiKey){
(function(p,e,n,d,o){var v,w,x,y,z;o=p[d]=p[d]||{};o._q=[];
v=['initialize','identify','updateOptions','pageLoad'];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://cdn.pendo.io/agent/static/'+apiKey+'/pendo.js';
z=e.getElementsByTagName(n)[0];z.parentNode.insertBefore(y,z);})(window,document,'script','pendo');
<% if signed_in? %>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we actually sign_in to Docuseal? Full disclosure: I am wholly ignorant here.

But since we iframe in everything and ping the app via API calls + tokens I assumed we didn't go through the regular auth process for Docuseal.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good question! Yeah they do, just not via the usual email/password.

When ATS iframes DocuSeal, it passes an auth_token in the URL. DocuSeal validates that token and signs the user in via Devise before any view renders, so by the time the layout loads, current_user and current_account are populated and signed_in? returns true.

The external_user_id and external_account_id fields on those records are how the ATS→DocuSeal mapping works (ATS user id and ATS account id respectively), which is what we use for the Pendo visitor/account ids so sessions stitch.

The else branch (pendo.initialize({})) is just a safety net for the edge case of someone hitting DocuSeal directly without going through the iframe. It lets Pendo still track anonymous sessions instead of erroring out when current_user is nil.

pendo.initialize({
visitor: { id: '<%= current_user.external_user_id || current_user.id %>' },
account: { id: '<%= current_account.external_account_id || current_account.id %>' }
});
<% else %>
pendo.initialize({});
<% end %>
})('<%= ENV.fetch('PENDO_API_KEY', nil) %>');
</script>
3 changes: 1 addition & 2 deletions lib/templates/process_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def generate_pdf_preview_images(attachment, data, pdf = nil)
attachment.save!
end

generate_document_preview_images(attachment, data, (0..number_of_pages - 1))
generate_document_preview_images(attachment, data, 0..number_of_pages - 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was including this change intentional?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I was fixing a rubocop that was annoying me.

end

def generate_document_preview_images(attachment, data, range, concurrency: CONCURRENCY)
Expand Down Expand Up @@ -196,6 +196,5 @@ def normalize_attachment_fields(template, attachments = template.documents)
pdf_fields
end
end

end
end
Loading