{"_id":"@bloomscorp/ngx-pixel","_rev":"2-b455b348ceb398551963e03117d901ea","name":"@bloomscorp/ngx-pixel","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@bloomscorp/ngx-pixel","description":"An Angular library to simplify the use of a Facebook Pixel. This is directly forked from https://github.com/NielsCodes/ngx-pixel since the library is no longer maintained.","author":{"name":"Debabrata Acharya","email":"debabrata@bloomscorp.com","url":"https://debacharya.com"},"license":"MIT","version":"0.0.1","repository":{"type":"git","url":"git+https://github.com/NielsKersic/ngx-pixel.git"},"keywords":["angular","facebook pixel","analytics","tracking","typescript"],"peerDependencies":{"@angular/common":">=17.1.1","@angular/core":">=17.1.1"},"dependencies":{"tslib":">=2.0.0"},"module":"fesm2022/bloomscorp-ngx-pixel.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2022":"./esm2022/bloomscorp-ngx-pixel.mjs","esm":"./esm2022/bloomscorp-ngx-pixel.mjs","default":"./fesm2022/bloomscorp-ngx-pixel.mjs"}},"sideEffects":false,"gitHead":"420a57d6d1d1fc44e9de940599400265c3313700","bugs":{"url":"https://github.com/NielsKersic/ngx-pixel/issues"},"homepage":"https://github.com/NielsKersic/ngx-pixel#readme","_id":"@bloomscorp/ngx-pixel@0.0.1","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-3PNhkeel0RpY5ieoQjsezbRw72wDQaOZDU5ippCeC9FF+OMrWh2O2f2lis0Kq95Ionq5737zS/+7uoMjAYVvXg==","shasum":"70ae49012c3b37f476302fe933e9296806695b5b","tarball":"https://registry.npmjs.org/@bloomscorp/ngx-pixel/-/ngx-pixel-0.0.1.tgz","fileCount":19,"unpackedSize":67663,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCdvUfFoiTobTIWZ4V0qLEJNi4UbkYirXBno+MrSUTuVQIhANQnM7oRDUuV8D/mRst7UzvzIz73ohbUUNFklGj1faP6"}]},"_npmUser":{"name":"debacharya","email":"debabrata@bloomscorp.com"},"directories":{},"maintainers":[{"name":"blacklist96","email":"ayankumarsaha96@gmail.com"},{"name":"debacharya","email":"debabrata@bloomscorp.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ngx-pixel_0.0.1_1707386958254_0.0006969864994346153"},"_hasShrinkwrap":false},"0.0.2":{"name":"@bloomscorp/ngx-pixel","description":"An Angular library to simplify the use of a Facebook Pixel. This is directly forked from https://github.com/NielsCodes/ngx-pixel since the library is no longer maintained.","author":{"name":"Debabrata Acharya","email":"debabrata@bloomscorp.com","url":"https://debacharya.com"},"license":"MIT","version":"0.0.2","repository":{"type":"git","url":"git+https://github.com/onclave/ngx-pixel.git"},"keywords":["angular","facebook pixel","analytics","tracking","typescript"],"peerDependencies":{"@angular/common":">=17.1.1","@angular/core":">=17.1.1"},"dependencies":{"tslib":">=2.0.0"},"module":"fesm2022/bloomscorp-ngx-pixel.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2022":"./esm2022/bloomscorp-ngx-pixel.mjs","esm":"./esm2022/bloomscorp-ngx-pixel.mjs","default":"./fesm2022/bloomscorp-ngx-pixel.mjs"}},"sideEffects":false,"gitHead":"bf6ce081987245ef9254924c7dfe4e72121a0e3e","bugs":{"url":"https://github.com/onclave/ngx-pixel/issues"},"homepage":"https://github.com/onclave/ngx-pixel#readme","_id":"@bloomscorp/ngx-pixel@0.0.2","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-TGPPWDhSqRM18CUcY7MlNU2kzLvVthheekThkuFDWQ8oExUAMDmeeabpQRUu9j6qVZomHGEkP53Z8pgzWY61oA==","shasum":"63d0e24ffa4cbc4e0bdf8e218f52bf17ec8a61d9","tarball":"https://registry.npmjs.org/@bloomscorp/ngx-pixel/-/ngx-pixel-0.0.2.tgz","fileCount":19,"unpackedSize":67659,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCo40s3F7RPtQMDmWDU3P2XEqTJrukVEXsxmVGGa4J6qwIhAMPJFj8SRTORkwL6+O2YvckNiKuEfk9PVYDGuBOFFJiE"}]},"_npmUser":{"name":"debacharya","email":"debabrata@bloomscorp.com"},"directories":{},"maintainers":[{"name":"blacklist96","email":"ayankumarsaha96@gmail.com"},{"name":"debacharya","email":"debabrata@bloomscorp.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ngx-pixel_0.0.2_1707387290460_0.6991449278381985"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-08T10:09:18.117Z","0.0.1":"2024-02-08T10:09:18.479Z","modified":"2024-04-04T10:45:14.215Z","0.0.2":"2024-02-08T10:14:50.596Z"},"maintainers":[{"email":"deepdey20998@gmail.com","name":"deepdey20998"},{"email":"ayankumarsaha96@gmail.com","name":"blacklist96"},{"email":"debabrata@bloomscorp.com","name":"debacharya"}],"description":"An Angular library to simplify the use of a Facebook Pixel. This is directly forked from https://github.com/NielsCodes/ngx-pixel since the library is no longer maintained.","homepage":"https://github.com/onclave/ngx-pixel#readme","keywords":["angular","facebook pixel","analytics","tracking","typescript"],"repository":{"type":"git","url":"git+https://github.com/onclave/ngx-pixel.git"},"author":{"name":"Debabrata Acharya","email":"debabrata@bloomscorp.com","url":"https://debacharya.com"},"bugs":{"url":"https://github.com/onclave/ngx-pixel/issues"},"license":"MIT","readme":"![ngx-pixel header](https://storage.googleapis.com/nielskersic/static-images/github/ngx-pixel%20header-min.png)\n\n<p align=\"center\">\nAn Angular library to simplify tracking using a Facebook Pixel.\n</p>\n\n---\n\n# Introduction\nUsing a Facebook Pixel is fairly simple. You add the script to the `head` section of all pages, after which you can use the `fbq` function. However, in Angular it's not as straight-forward. The main two problems are as follows:\n\n- Navigation using the Angular Router is not tracked.\n- There are no TypeScript definitions by default, so no Intellisense or linting.\n\n***ngx-pixel*** solves both of these issues. It adds a service that can be used in any component to track events and when enabled, it automatically tracks page views for each router navigation. \n\nBy default, ***ngx-pixel*** is **disabled** to make it easier to comply with GDPR and other privacy regulations. The Facebook script is only loaded after ***ngx-pixel*** is enabled, which also helps cut down the initial load time of your application. Read [here](#enabling) how to *enable* and *disable* ***ngx-pixel***.\n\n---\n\n# Usage\nUsing ***ngx-pixel*** is very simple.\n\n## 1. Installing the NPM package\nYou can install the NPM package with `npm install ngx-pixel`\n\n## 2. Add it to your app module\nAdd the library to your app's module, usually `app.module.ts`. Make sure you use the `forRoot()` method. Within this method, add your [Facebook Pixel ID](https://www.facebook.com/business/help/952192354843755). \n```typescript\nimport { PixelModule } from 'ngx-pixel';\n\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    BrowserModule,\n    PixelModule.forRoot({ enabled: true, pixelId: 'YOUR_PIXEL_ID' })\n  ],\n  providers: [],\n  bootstrap: [AppComponent]\n})\nexport class AppModule { }\n```\n**NOTE:** By default, the library does not start tracking immediately. In most cases this requires user consent to comply with GDPR and other privacy regulations. If you would still like start tracking as soon as your app module loads, include the `enabled: true` parameter in when you call `forRoot()`.\n\n## 3. Add it to your components\nIn any component where you would like to track certain events, you can import the ***ngx-pixel service*** with `import { PixelService } from 'ngx-pixel';`\nThen you can inject the service into your component as follows:\n```TypeScript\nexport class HomeComponent {\n\n  constructor(\n    private pixel: PixelService\n  ) { }\n\n}\n```\n\n## 4. Tracking events\nThere are two groups of events that you can track, namely *Standard events*  and *Custom events*. \n\n### Standard events\n**Standard events** are common events that Facebook has created. You can find the full list [here](https://developers.facebook.com/docs/facebook-pixel/reference). You can track a Standard event like this:\n![Track Standard events using ngx-pixel](https://storage.googleapis.com/nielskersic/static-images/github/ngx-pixel-track-large.gif)\n\nThe first argument is the type of event as defined by Facebook. The optional second argument can be used to pass more information about the event. E.g.: \n```typescript\nthis.pixel.track('InitiateCheckout', {\n  content_ids: ['ABC123', 'XYZ456'],  // Item SKUs\n  value: 100,                         // Value of all items\n  currency: 'USD'                     // Currency of the value\n});\n```\n\n### Custom events\nTracking **Custom events** works very similar to tracking Standard events. The only major difference is that there are no TypeScript interfaces and therefore no Intellisense. This is because the event *name* and optional *properties* can be anything. Tracking a custom event with ***ngx-pixel*** looks like this:\n```TypeScript\nthis.pixel.trackCustom('MyCustomEvent');\n```\n\nAnd just like with Standard events, you can add more properties. This is recommended, since this enables you to create even more specific audiences within Facebook Business Manager. Which properties you add is completely up to you. Here is an example:\n```TypeScript\nthis.pixel.trackCustom('MyCustomEvent', {\n  platform: 'limewire'\n})\n```\n\n---\n\n# Enabling and disabling ***ngx-pixel*** <a name=\"enabling\"></a>\n***ngx-pixel*** is disabled by default. In many cases, tracking without user consent is not allowed by privacy regulations like the European GDPR. ***ngx-pixel*** also doesn't inject the Facebook scripts until it is iniaitlized (upon consent), which helps cut down the initial loading size and time of your application.\n\n## Enabling ***ngx-pixel*** immediately\nIt is still possible to initialize ***ngx-pixel*** as soon as your app module loads.\nWhen adding ***ngx-pixel*** to `app.module.ts`, add the parameter `enabled: true`.\n```TypeScript\nimports: [\n  BrowserModule,\n  PixelModule.forRoot({ enabled: true, pixelId: 'YOUR_PIXEL_ID'})\n],\n```\n\n## Enabling ***ngx-pixel*** from a component\nYou can also enable ***ngx-pixel*** from within any of your components, like so:\n```TypeScript\nexport class HomeComponent {\n\n  constructor(\n    private pixel: PixelService\n  ) { }\n\n  onConsent(): void {\n    this.pixel.initialize();\n  }\n\n}\n```\n\n## Enabling with a dynamic Pixel ID\nIn situations where the Pixel ID needs to be changed dynamically, this can be done using `initialize()` with the new Pixel ID as an optional argument. \n**Notes:** \n- A Pixel ID still needs to be provided when importing ***ngx-pixel*** in the module.\n- The previous instance should be removed with `remove()` before initializing a new Pixel ID. \n- This approach should **not** be used in combination with serverside rendering (SSR). As the module is initialized on each request, the Pixel script will default to the ID provided in the module.  \n\n## Disabling ***ngx-pixel***\nDisabling works very similar to *enabling* from within a component and looks like this:\n```TypeScript\nexport class HomeComponent {\n\n  constructor(\n    private pixel: PixelService\n  ) { }\n\n  onRevokeConsent(): void {\n    this.pixel.remove();\n  }\n\n}\n```\n\n---\n\n# Important notes\n- Backwards compatibility is not guaranteed. ***ngx-pixel*** was developed using Angular 11, which uses the Ivy compiler instead of the older View Engine compiler. If your project uses Angular 8 or earlier, or if you've decided to keep using View Engine with newer Angular versions, ***ngx-pixel*** might not be compatible, although I have not yet tested this to confirm.\n\n---\n\n# What's next?\n- [X] Adding Angular Universal SSR support.\n- [ ] Adding tests.\n- [ ] Removing all Facebook scripts on removal, not just the initial script.\n\n---\n\nCreated with ❤️ by Niels Kersic, [niels.codes](https://niels.codes).\n\n\n\n\n\n\n\n","readmeFilename":"README.md"}