Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the Freshdesk/Freshdesk Widget with Turbolinks #89

Open
nodunayo opened this issue Mar 23, 2021 · 4 comments
Open

Using the Freshdesk/Freshdesk Widget with Turbolinks #89

nodunayo opened this issue Mar 23, 2021 · 4 comments

Comments

@nodunayo
Copy link

nodunayo commented Mar 23, 2021

Hello,

I’ve been using the Freshdesk widget on my production app for a while now. I want to be able to pre-fill a user's email address as well as automatically set the ticket priority for my paid users to "High".

I've got it set up such that on the initial website loads or page refreshes, everything works as is expected, but when navigating from page-to-page within the app, only the widget is initialised, but none of the extra stuff is set up.

Here's how my code is set up.

In app/views/layouts/application.html.erb, just before the closing </body> tag, I have:

<%= render "layouts/freshdesk_widget" %>

Inside app/views/layouts/_freshdesk_widget.html.erb, I have the following:

<script>
  window.fwSettings={
      'widget_id':<widget_id>
    };
  !function(){if("function"!=typeof window.FreshworksWidget){var n=function(){n.q.push(arguments)};n.q=[],window.FreshworksWidget=n}}()
</script>
<script type='text/javascript' src='https://euc-widget.freshworks.com/widgets/<widget_id>.js' async defer></script>
<script type='text/javascript'>
  FreshworksWidget('identify', 'ticketForm', { email: '<%= "#{current_user.try(:email)}" %>' });
  FreshworksWidget('hide', 'ticketForm', ['priority']);
  FreshworksWidget('prefill', 'ticketForm', { priority: <%= current_user.try(:paid?) ? 3 : 1 %> });
</script>

I’ve tried many different things, from trying to call the code in different places, to trying to manually do what I want, but to no avail.

Ever since I started using this widget, when navigating to other pages after the initial page load, I always get the following error in my console:

VM2797 <widget_id>.js:1 Uncaught TypeError: Cannot read property 'postMessage' of null
    at Object.postMessage (VM2797 <widget_id>.js:1)
    at Object.widgetRenderComplete (VM2797 <widget_id>.js:1)
    at Object.handleMessage (VM2797 <widget_id>.js:1)

I did get rid of these errors by putting the embed code in the <head> of application.html.erb, but it meant the widget didn’t load again beyond the initial page load. So, I put everything back to where the documentation said it should go and have just been ignoring the error message. I wonder whether it has any bearing on the problems I’m having now.

Thank you in advance for any help I get! Let me know if you have any more questions or need to see more parts of the code.

@nodunayo nodunayo changed the title Using the Freshworks Widget with Turbolinks Using the Freshdesk Widget with Turbolinks Mar 29, 2021
@nodunayo nodunayo changed the title Using the Freshdesk Widget with Turbolinks Using the Freshdesk/Freshdesk Widget with Turbolinks Mar 29, 2021
@belumarek
Copy link

Hello @nodunayo I'm facing the same issue, have you been able to resolve it?

@nodunayo
Copy link
Author

nodunayo commented Apr 7, 2021

Hello @nodunayo I'm facing the same issue, have you been able to resolve it?

HI @belumarek — I haven't, I'm afraid. Hoping to spend more time looking into it this week. Let me know if you find anything!

@nodunayo
Copy link
Author

HI @belumarek — have you found anything on this? I'd really appreciate some help!

@nodunayo
Copy link
Author

Hi @belumarek — wait, where does Sentry come into it? Not sure how it's related to the issue. I'm not using Sentry for one!

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

No branches or pull requests

2 participants