question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add documentation on how to use insights middleware in Nuxt

See original GitHub issue

Bug 🐞

What is the current behavior?

Currenly i’m using ais-instantsearch-ssr and i want to add algolia analytics to this. But right now i get some errors regarding the server side rendering and etc.

What is the expected behavior?

Track searchs, clicks, and conversions with insights.

RIght now i get a window is not defined when i add insights to data like this:

data() {
        // Created in `data` to access the Vue Router
        const mixin = createServerRootMixin({
            searchClient: getSearchClient(),
            indexName: process.env.indice,
            clickAnalytics: true,
            replicas: [
                `SortByDESC ${process.env.commerceCulture}`,
                `SortByASC ${process.env.commerceCulture}`,
                `SortByLaunch ${process.env.commerceCulture}`,
                `SortByDiscountDESC ${process.env.commerceCulture}`
            ],
            routing: {
                router: nuxtRouter(this.$router),
                stateMapping:  singleIndex(process.env.indice),
            },
        });
        return {
            ...mixin.data(),
            insightsClient: window.aa,
        };
    },

is there a fix to this? if i add it in beforeMount i get this error on clicks: image

Do you have a working example with insights enabled in nuxt?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Haroenvcommented, Jul 15, 2021

it would be this.insightsClient, but yes

1reaction
francoischalifourcommented, Jul 15, 2021

Hey! I guess Nuxt doesn’t have access to the window object when rendering on the server. Can you try to install search-insights in your project, and to import Search Insights in your file?

import insightsClient from 'search-insights';

// ...

export default {
  data() {
    // ...
    return {
      ...mixin.data(),
      insightsClient,
    };
  },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Middleware directory - Nuxt
The middleware directory contains your application middleware. ... define page-specific middleware by using a function directly, see anonymous middleware .
Read more >
Creating Server-side Rendered Vue.js Apps Using Nuxt.js
Nuxt provides a way to customize the router instance in the config, allowing you to add new routes and customize generated routes. You...
Read more >
Universal application code structure in Nuxt.js - freeCodeCamp
Since Nuxt uses connect to deliver the application, it allows custom functions to be hooked into the underlying request pipeline as middleware.
Read more >
Add 2FA to Your Nuxt Application with Nexmo Verify
Nuxt is a framework for building 'Universal Vue.js Applications'. Essentially, this means that when you use Nuxt you have the option of building ......
Read more >
Monitor your Node.js services and apps with Application Insights
You can use Application Insights for Node.js services that are hosted in ... Add the Node.js client library to your app's dependencies via ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found