NielsCodes / ngx-pixel

An Angular library to simplify event tracking using a Facebook Pixel.
https://www.npmjs.com/package/ngx-pixel
13 stars 15 forks source link

document is not defined in "SSR Angular Universal" #2

Closed samizarraa closed 3 years ago

samizarraa commented 3 years ago

Hi Please can you Inject Document instead of use it directly @Inject(DOCUMENT) private readonly doc: Document I want to use it in SSR

Thanks

samizarraa commented 3 years ago

Hi Any news to fix this issue. Thanks

NielsCodes commented 3 years ago

This fix will be included in the next update! Sorry for not getting to this sooner.

NielsCodes commented 3 years ago

@samizarraa I've taken a look at this issue and decided to not include it in the newest release yet. While the 'document is not defined' error can indeed be fixed by injecting the DOCUMENT from @angular/common, the Facebook script is still not accessible from within the service.

I'll be doing some more research on how to resolve this issue to add support for SSR.

l4nos commented 3 years ago

Great work on the plugin, it's a really handy tool to have.

As for SSR, You don't need to fire pixel events serverside, if anything its better not to or you'll have events firing twice, just simply surround the doucment reference in a isPlatformBrowser check surely?

Really need this to be updated as im trying to put a commercial project live, if you can't manage it in the next day or two please let me know and I'll work on another solution.

NielsCodes commented 3 years ago

@syn6UK right now I'm not getting any fired events at all. I don't know if I'll be able to get this fixed on the next two days, but of course I'd be more than happy to accept a PR or code snippet if you manage to find a solution!

l4nos commented 3 years ago

I'll have a crack at it, i'll keep you updated.

l4nos commented 3 years ago

Can you give me write permissions to upload my branch?

NielsCodes commented 3 years ago

@syn6UK only the 'main' branch should be protected. What branch are you trying to push to?

l4nos commented 3 years ago

I've put a pull request in now :) Sorry, lack of coffee!

NielsCodes commented 3 years ago

@syn6UK Thanks! I'll review in the morning

l4nos commented 3 years ago

Can confirm from testing on my production site, it works fine!

samizarraa commented 3 years ago

@syn6UK @NielsKersic Hi Actually, I no longer use the plugin due to the Facebook Pixel added to Google Tags manager.

l4nos commented 3 years ago

Are you using a plugin for this or vanilla js integration?

samizarraa commented 3 years ago

I just use Facebook tag template in google tags manager and after that just add pixel id, Done

NielsCodes commented 3 years ago

@syn6UK I've just published a new release (1.1.0) with added SSR support :)