segmentio / analytics.js

The hassle-free way to integrate analytics into any web application.
https://segment.com/libraries/analytics.js
MIT License
4.77k stars 736 forks source link

Uncaught TypeError: Cannot read property 'replace' of undefined #634

Open AvocadoVenom opened 4 years ago

AvocadoVenom commented 4 years ago

Hello team,

I get a strange error at the first Page Datalayer in my app.

My application is a Vue CLI 2.6 with Typescript.

I send event with the following:

;(window as any).analytics &&
    (window as any).analytics.track(eventName, payload, { Intercom: false })

eventName is a string like undefined_event or any other custom string.

payload is a key-value pair dictionary which may contain null value.

My code to send the Page Datalayer:

const options = {
   name: to.path,
   title: document.title,
   path: to.fullPath,
   search: JSON.stringify(to.query)
 }

;(window as any).analytics.track('Page Datalayer', options)

Here is the warning I get:

[Amplitude] Invalid eventType input type. Expected string but received undefined

Here is the stackTrace:

cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:8 Uncaught TypeError: Cannot read property 'replace' of undefined
    at a (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:8)
    at o (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:8)
    at t.n.map (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:1)
    at t.<computed> [as standardEvents] (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:2)
    at t.f.track (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:7)
    at track (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:1)
    at cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:1
    at u (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:3)
    at c (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:3)
    at t.n.flush (cdn.segment.com/analytics.js/v1/jExWYocq8leIbsvVJRF9eymTCah0P4qr/analytics.min.js:1)

My events have the following data structure:

{
  "timestamp": "2020-08-26T15:05:58.289Z",
  "integrations": {
    "Intercom": false
  },
  "context": {
    "page": {
      "path": "/my-path/",
      "referrer": "my-referrer",
      "search": "",
      "title": "Title",
      "url": "my-url"
    },
    "userAgent": "something",
    "locale": "en-GB",
    "library": {
      "name": "analytics.js",
      "version": "3.13.6"
    }
  },
  "properties": {
    "id": "A-Dasherized-Custom-Id",
    "type": "undefined_event",
    "properties": {
      "a": "a",
      "key": "key",
      "value": "value",
      "pair": "pair",
      "dico": "dico"
      "with": "with",
      "string": "string",
      "null": null,
      "int": 0,
      "values": "values"
    }
  },
  "event": "Undefined Event",
  "messageId": "messageId",
  "anonymousId": "anonymousId",
  "type": "track",
  "writeKey": "my-write-key",
  "userId": 1234,
  "sentAt": "2020-08-26T15:05:58.295Z",
  "_metadata": {
    "bundled": [
      "Amplitude",
      "Facebook Pixel",
      "Google Analytics",
      "Google Tag Manager",
      "Intercom",
      "Segment.io"
    ],
    "unbundled": []
  }
}

I guess you will need further information so feel free to ask

Many thanks

pooyaj commented 4 years ago

Hi @AvocadoVenom, do you have the app accessible somewhere so I can reproduce/debug the issue?