Amplitude-JavaScript icon indicating copy to clipboard operation
Amplitude-JavaScript copied to clipboard

amplitude is not defined

Open kunjan97 opened this issue 3 years ago • 4 comments

I have use amplitude-js in angular ssr but it gives me error like this

amplitude is not defined

If have any suggestion Please help me out.

kunjan97 avatar Jan 27 '22 06:01 kunjan97

Hi @kunjan97, thanks for submitting an issue. Can you provide a code snippet so we can assess this issue further?

kevinpagtakhan avatar Jan 27 '22 09:01 kevinpagtakhan

In Index.html

I have Loaded Amplitude-js like this.

And I have use Amplitude service for log event and user property events

import { Injectable } from '@angular/core'; import { environment } from 'src/environments/environment'; declare var amplitude;

@Injectable({ providedIn: 'root' }) export class AmplitudeService {

constructor() { this.initAmplitude(); }

public initAmplitude() { amplitude.getInstance().init(environment.amplitudeAPIKey, null, { saveEvents: true, includeUtm: true, includeReferrer: true, deviceIdFromUrlParam: true }); }

public logEvent(eventName, eventValue) { amplitude.getInstance().logEvent(eventName, eventValue); return this; }

public setAmplitudeUserId(userId) { amplitude.getInstance().setUserId(userId); }

public setUserProperties(user) { amplitude.getInstance().setUserProperties(user); return this; } }

kunjan97 avatar Jan 27 '22 09:01 kunjan97

Hey @kunjan97, you mentioned this is angular SSR. Does AmplitudeService run on the sever-side? If so, <script src="./assets/js/amplitude.js"></script> does not work on the server-side in this case.

dnshi avatar Mar 25 '22 21:03 dnshi

Hi All, Any solution for this issue ?

eksant avatar Mar 06 '23 07:03 eksant