matomo-org / matomo-nodejs-tracker

A Node.js wrapper for the Matomo (Piwik) tracking HTTP API
MIT License
117 stars 41 forks source link

Unable to determine the domain name #65

Closed Regnised closed 4 years ago

Regnised commented 4 years ago

Issue: I'm getting the error. Unable to determine the domain name -- TypeError [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name\n at new ClientRequest (_http_client.js:71:13)\n at request (http.js:42:10)\n at Object.get (http.js:46:13)\n at MatomoTracker.track (/.../node_modules/matomo-tracker/index.js:72:24)\n at MatomoLinkService.track (/.../matomo-link.service.js:23:21)\n at new MatomoLinkService (/.../matomo-link.service.js:20:14)\n at Injector.instantiateClass (/.../node_modules/@nestjs/core/injector/injector.js:289:19)\n at callback (/.../node_modules/@nestjs/core/injector/injector.js:76:41)\n at process._tickCallback (internal/process/next_tick.js:68:7)\n at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)"}

Expect: I send track event to matomo dashboard

My code:

import { Injectable } from '@nestjs/common';
import * as MatomoTracker from 'matomo-tracker';

@Injectable()
export class MatomoLinkService {
    private matomoUrl = process.env.MATOMO_URL || 'example.de';
    private matomoId = process.env.MATOMO_ID || '1';
    private matomoTracker: MatomoTracker;
    matomo;
    constructor() {
        this.matomo = new MatomoTracker(this.matomoId, this.matomoUrl, true);
        console.log('this.matomo ==== ', this.matomo);
        this.track({});
    }

    track(event: object): void {
        this.matomo.track('Test 2');
    }
}
`

Console.log info:


this.matomo ====  MatomoTracker {
  domain: null,
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  siteId: '1',
  trackerUrl: 'example.de',
  agent:
   { _connectionListener: [Function: connectionListener],
     METHODS:
      [ 'ACL',
        'BIND',
        'CHECKOUT',
        'CONNECT',
        'COPY',
        'DELETE',
        'GET',
        'HEAD',
        'LINK',
        'LOCK',
        'M-SEARCH',
        'MERGE',
        'MKACTIVITY',
        'MKCALENDAR',
        'MKCOL',
        'MOVE',
        'NOTIFY',
        'OPTIONS',
        'PATCH',
        'POST',
        'PROPFIND',
        'PROPPATCH',
        'PURGE',
        'PUT',
        'REBIND',
        'REPORT',
        'SEARCH',
        'SOURCE',
        'SUBSCRIBE',
        'TRACE',
        'UNBIND',
        'UNLINK',
        'UNLOCK',
        'UNSUBSCRIBE' ],
     STATUS_CODES:
      { '100': 'Continue',
        '101': 'Switching Protocols',
        '102': 'Processing',
        '103': 'Early Hints',
        '200': 'OK',
        '201': 'Created',
        '202': 'Accepted',
        '203': 'Non-Authoritative Information',
        '204': 'No Content',
        '205': 'Reset Content',
        '206': 'Partial Content',
        '207': 'Multi-Status',
        '208': 'Already Reported',
        '226': 'IM Used',
        '300': 'Multiple Choices',
        '301': 'Moved Permanently',
        '302': 'Found',
        '303': 'See Other',
        '304': 'Not Modified',
        '305': 'Use Proxy',
        '307': 'Temporary Redirect',
        '308': 'Permanent Redirect',
        '400': 'Bad Request',
        '401': 'Unauthorized',
        '402': 'Payment Required',
        '403': 'Forbidden',
        '404': 'Not Found',
        '405': 'Method Not Allowed',
        '406': 'Not Acceptable',
        '407': 'Proxy Authentication Required',
        '408': 'Request Timeout',
        '409': 'Conflict',
        '410': 'Gone',
        '411': 'Length Required',
        '412': 'Precondition Failed',
        '413': 'Payload Too Large',
        '414': 'URI Too Long',
        '415': 'Unsupported Media Type',
        '416': 'Range Not Satisfiable',
        '417': 'Expectation Failed',
        '418': 'I\'m a Teapot',
        '421': 'Misdirected Request',
        '422': 'Unprocessable Entity',
        '423': 'Locked',
        '424': 'Failed Dependency',
        '425': 'Unordered Collection',
        '426': 'Upgrade Required',
        '428': 'Precondition Required',
        '429': 'Too Many Requests',
        '431': 'Request Header Fields Too Large',
        '451': 'Unavailable For Legal Reasons',
        '500': 'Internal Server Error',
        '501': 'Not Implemented',
        '502': 'Bad Gateway',
        '503': 'Service Unavailable',
        '504': 'Gateway Timeout',
        '505': 'HTTP Version Not Supported',
        '506': 'Variant Also Negotiates',
        '507': 'Insufficient Storage',
        '508': 'Loop Detected',
        '509': 'Bandwidth Limit Exceeded',
        '510': 'Not Extended',
        '511': 'Network Authentication Required' },
     Agent:
      { [Function: Agent] super_: [Function], defaultMaxSockets: Infinity },
     ClientRequest: { [Function: ClientRequest] super_: [Function] },
     IncomingMessage: { [Function: IncomingMessage] super_: [Function] },
     OutgoingMessage: { [Function: OutgoingMessage] super_: [Function] },
     Server: { [Function: Server] super_: [Function] },
     ServerResponse: { [Function: ServerResponse] super_: [Function] },
     createServer: [Function: createServer],
     get: [Function: get],
     request: [Function: request],
     maxHeaderSize: [Getter],
     globalAgent: [Getter/Setter] } }

`
Regnised commented 4 years ago

Oh, I should add http:// or https:// to matomoUrl.