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.

Node.js example not working

See original GitHub issue

Hi, this seems like a great library and it is exactly what I need for my project. However, I can’t get it to work in my node.js application. Even the basic example from the documentation is not working for me:

const analyticsLib = require('analytics').default
const googleAnalytics = require('@analytics/google-analytics').default

const analytics = analyticsLib({
  app: 'my-app-name',
  plugins: [
    googleAnalytics({
      trackingId: '123-xyz'
    })
  ]
})

/* Track a page view */
analytics.page()

Using analytics.page() throws an error (Error: Missing path, href or title in page call for GA). If I do the following:

analytics.page({
    title: 'test',
    href: 'http://localhost:3000',
    path: '/'
})

the code runs, but I don’t see any page event in Google Analytics. And of course, I replaced the trackingId from the sample code with my own.

Any hints that can help me to get page views tracked?

Thanks!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
markojakcommented, Aug 23, 2021

A few tings:

  1. Enable debug: true just under “app” - If you are seeing that https://getanalytics.io/debugging/ is giving you the page() hit then the analytics module is working and you’re trying to do something non-standard

  2. Have you installed the relevant packages? You’ll need

import Analytics from 'analytics'
import googleAnalytics from '@analytics/google-analytics'
  1. You don’t need to specify any custom attributes for the page() call. What it seems like you’re doing is attempting to define custom dimensions without first defining them in GA? Read this: https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
0reactions
DavidWellscommented, Oct 24, 2021

When using just page() I keep getting ‘Error: Missing path, href or title in page call for GA’. Just FYI.

Yep those are required from the underlying lib https://github.com/DavidWells/analytics/blob/master/packages/analytics-plugin-google-analytics/src/node.js#L59

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 reasons your Node.js apps are failing - IBM Developer
6 reasons your Node.js apps are failing · 1. Uncaught exceptions or error events in JavaScript code · 2. Excessive memory usage, which...
Read more >
Node.js Hello World not working - Stack Overflow
I'm trying to get my node.js Hello World code to work. My problem is that when I try to run my "Hello World"...
Read more >
Top 10 Most Common Node.js Developer Mistakes - Toptal
Mistake #5: Assigning to “exports”, Instead of “module. exports” Node. js treats each file as a small isolated module.
Read more >
Errors | Node.js v19.3.0 Documentation
Node.js generates system errors when exceptions occur within its runtime environment. These usually occur when an application violates an operating system ...
Read more >
Node.js Error: Cannot GET/ from running the url on the web ...
Problem Statement: On running a Node. · Example: Let's create a simple Node. · Step 1: Initializes NPM: · Step 2: Install Dependencies:...
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