Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amplitude is not defined #494

Open
kunjan97 opened this issue Jan 27, 2022 · 4 comments
Open

amplitude is not defined #494

kunjan97 opened this issue Jan 27, 2022 · 4 comments
Labels
question Further information is requested

Comments

@kunjan97
Copy link

kunjan97 commented Jan 27, 2022

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 kunjan97 added the question Further information is requested label Jan 27, 2022
@kevinpagtakhan
Copy link
Contributor

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

@kunjan97
Copy link
Author

In Index.html

<script src="./assets/js/amplitude.js"></script>

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;
}
}

@dnshi
Copy link
Contributor

dnshi commented Mar 25, 2022

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.

@eksant
Copy link

eksant commented Mar 6, 2023

Hi All,
Any solution for this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants