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

Cannot initilizate intercom manually #28

Open
cstriuli opened this issue Jul 20, 2021 · 3 comments
Open

Cannot initilizate intercom manually #28

cstriuli opened this issue Jul 20, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@cstriuli
Copy link

Hi there 🙌,

First of all, thanks for the module! Awesome work.

About the issue

I've got a special case where I need to initialize the Intercom through an API using differents App ID's, so for example:

  • domain.com/us should load the app id XXX-1
  • domain.com/jp should load the app id XXX-2
  • domain.com/uk should load the app id XXX-3

So I've tried to boot manually from a custom plugin in nuxt like this:

export default({$intercom, store}) => {
   const appId = store.state.country.intercomAppId
   $intercom.boot({app_id: appId})
}

But it doesn't work because the module isn't being loaded if the nuxt.config.js doesn't contain a valid app_id, so there's no way to initialize the plugin manually.

Would you mind checking the following code?

if (!options.appId) {

Could I help to send a PR or let me know if I'm doing something wrong?

Thanks!

@Jamiewarb
Copy link
Member

Jamiewarb commented Jul 20, 2021

Ah interesting.

I believe the appId parameter can take a function, so rather than just a variable, you should be able to pass in a function that will resolve to the appId that you need.

Would that work for you?

https://github.com/hex-digital/nuxt-intercom/blob/master/lib/module.js#L11

// Async id evaluation
if (typeof (options.appId) === 'function') {
  options.appId = await options.appId()
}

@cstriuli
Copy link
Author

Ah interesting.

I believe the appId parameter can take a function, so rather than just a variable, you should be able to pass in a function that will resolve to the appId that you need.

Would that work for you?

https://github.com/hex-digital/nuxt-intercom/blob/master/lib/module.js#L11

// Async id evaluation
if (typeof (options.appId) === 'function') {
  options.appId = await options.appId()
}

Oh, I forgot to mention it, but I have tried to use that option 🙁

The problem is that I have no way of identifying the country from the callback of the nuxt.config.js. So, to identify the country, I'm using the current route + nuxtServerInit method + a store to hold the information.

@Jamiewarb
Copy link
Member

Ah okay fair enough. In that case, yes please feel free to suggest a better solution for it and/or submit a PR, that would be extremely useful!

@Jamiewarb Jamiewarb added the enhancement New feature or request label May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants