Skip to content

Commit 6117342

Browse files
committed
📚 Updated README
1 parent fdad2d1 commit 6117342

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

README.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ Using a Facebook Pixel is fairly simple. You add the script to the `head` sectio
1414
- Navigation using the Angular Router is not tracked.
1515
- There are no TypeScript definitions by default, so no Intellisense or linting.
1616

17-
***ngx-pixel*** solves both of these issues.
17+
***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.
18+
19+
By 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***.
20+
21+
---
1822

1923
## Usage
2024
Using ***ngx-pixel*** is very simple.
@@ -84,13 +88,65 @@ this.pixel.trackCustom('MyCustomEvent', {
8488
})
8589
```
8690

91+
---
92+
93+
## Enabling and disabling ***ngx-pixel*** <a name="enabling"></a>
94+
***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.
95+
96+
### Enabling ***ngx-pixel*** immediately
97+
It is still possible to initialize ***ngx-pixel*** as soon as your app module loads.
98+
When adding ***ngx-pixel*** to `app.module.ts`, add the parameter `enabled: true`.
99+
```TypeScript
100+
imports: [
101+
BrowserModule,
102+
PixelModule.forRoot({ enabled: true, pixelId: 'YOUR_PIXEL_ID'})
103+
],
104+
```
105+
106+
### Enabling ***ngx-pixel*** from a component
107+
You can also enable ***ngx-pixel*** from within any of your components, like so:
108+
```TypeScript
109+
export class HomeComponent {
110+
111+
constructor(
112+
private pixel: PixelService
113+
) { }
114+
115+
onConsent(): void {
116+
this.pixel.initialize();
117+
}
118+
119+
}
120+
```
121+
122+
### Disabling ***ngx-pixel***
123+
Disabling works very similar to *enabling* from within a component and looks like this:
124+
```TypeScript
125+
export class HomeComponent {
126+
127+
constructor(
128+
private pixel: PixelService
129+
) { }
130+
131+
onRevokeConsent(): void {
132+
this.pixel.remove();
133+
}
134+
135+
}
136+
```
137+
138+
---
139+
87140
## Important notes
88-
- ***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 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.
141+
- 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 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.
142+
143+
---
89144

90145
## What's next?
91-
- [ ] Checking Pixel ID's using a RegEx. I first want to confirm whether all Pixel ID's follow the same format.
146+
- [ ] Checking Pixel ID's using a RegEx. First need to confirm whether all Pixel ID's follow the same format.
92147
- [ ] Adding tests.
93148
- [ ] Testing View Engine backwards-compatibility.
149+
- [ ] Removing all Facebook scripts on removal, not just the initial script.
94150

95151
---
96152
<center>

projects/pixel/src/lib/pixel.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import { PixelService } from './pixel.service';
88
})
99
export class PixelModule {
1010

11-
private static config: PixelConfiguration;
11+
private static config: PixelConfiguration | null = null;
1212

1313
constructor( private pixel: PixelService ) {
14+
if (!PixelModule.config) {
15+
throw Error('ngx-pixel not configured correctly');
16+
}
1417
if (PixelModule.config.enabled) {
1518
this.pixel.initialize();
1619
}

0 commit comments

Comments
 (0)