You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple Angular library to simplify tracking using a Facebook Pixel.
7
-
</center>
3
+
<palign="center">
4
+
An Angular library to simplify tracking using a Facebook Pixel.
5
+
</p>
8
6
9
7
---
10
8
11
-
##Introduction
9
+
# Introduction
12
10
Using 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:
13
11
14
12
- Navigation using the Angular Router is not tracked.
@@ -20,13 +18,13 @@ By default, ***ngx-pixel*** is **disabled** to make it easier to comply with GDP
20
18
21
19
---
22
20
23
-
##Usage
21
+
# Usage
24
22
Using ***ngx-pixel*** is very simple.
25
23
26
-
###1. Installing the NPM package
24
+
## 1. Installing the NPM package
27
25
You can install the NPM package with `npm install ngx-pixel`
28
26
29
-
###2. Add it to your app module
27
+
## 2. Add it to your app module
30
28
Add 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).
31
29
```typescript
32
30
import { PixelModule } from'ngx-pixel';
@@ -46,7 +44,7 @@ export class AppModule { }
46
44
```
47
45
**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()`.
48
46
49
-
###3. Add it to your components
47
+
## 3. Add it to your components
50
48
In any component where you would like to track certain events, you can import the ***ngx-pixel service*** with `import { PixelService } from 'ngx-pixel';`
51
49
Then you can inject the service into your component as follows:
52
50
```TypeScript
@@ -59,10 +57,10 @@ export class HomeComponent {
59
57
}
60
58
```
61
59
62
-
###4. Tracking events
60
+
## 4. Tracking events
63
61
There are two groups of events that you can track, namely *Standard events* and *Custom events*.
64
62
65
-
####Standard events
63
+
### Standard events
66
64
**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:
67
65

Tracking **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:
##Enabling and disabling ***ngx-pixel*** <aname="enabling"></a>
91
+
# Enabling and disabling ***ngx-pixel*** <aname="enabling"></a>
94
92
***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
93
96
-
###Enabling ***ngx-pixel*** immediately
94
+
## Enabling ***ngx-pixel*** immediately
97
95
It is still possible to initialize ***ngx-pixel*** as soon as your app module loads.
98
96
When adding ***ngx-pixel*** to `app.module.ts`, add the parameter `enabled: true`.
99
97
```TypeScript
@@ -103,7 +101,7 @@ imports: [
103
101
],
104
102
```
105
103
106
-
###Enabling ***ngx-pixel*** from a component
104
+
## Enabling ***ngx-pixel*** from a component
107
105
You can also enable ***ngx-pixel*** from within any of your components, like so:
108
106
```TypeScript
109
107
exportclassHomeComponent {
@@ -119,7 +117,7 @@ export class HomeComponent {
119
117
}
120
118
```
121
119
122
-
###Disabling ***ngx-pixel***
120
+
## Disabling ***ngx-pixel***
123
121
Disabling works very similar to *enabling* from within a component and looks like this:
124
122
```TypeScript
125
123
exportclassHomeComponent {
@@ -137,21 +135,21 @@ export class HomeComponent {
137
135
138
136
---
139
137
140
-
##Important notes
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.
138
+
# Important notes
139
+
- 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.
142
140
143
141
---
144
142
145
-
##What's next?
143
+
# What's next?
146
144
-[ ] Checking Pixel ID's using a RegEx. First need to confirm whether all Pixel ID's follow the same format.
147
145
-[ ] Adding tests.
148
146
-[ ] Testing View Engine backwards-compatibility.
149
147
-[ ] Removing all Facebook scripts on removal, not just the initial script.
150
148
151
149
---
152
-
<center>
153
-
Created with ❤️ by Niels Kersic, [niels.codes](https://niels.codes).
154
-
</center>
150
+
151
+
Created with ❤️ by Niels Kersic, [niels.codes](https://google.com).
A simple Angular library to simplify tracking using a Facebook Pixel.
7
-
</center>
3
+
<palign="center">
4
+
An Angular library to simplify tracking using a Facebook Pixel.
5
+
</p>
8
6
9
7
---
10
8
11
-
##Introduction
9
+
# Introduction
12
10
Using 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:
13
11
14
12
- Navigation using the Angular Router is not tracked.
@@ -20,13 +18,13 @@ By default, ***ngx-pixel*** is **disabled** to make it easier to comply with GDP
20
18
21
19
---
22
20
23
-
##Usage
21
+
# Usage
24
22
Using ***ngx-pixel*** is very simple.
25
23
26
-
###1. Installing the NPM package
24
+
## 1. Installing the NPM package
27
25
You can install the NPM package with `npm install ngx-pixel`
28
26
29
-
###2. Add it to your app module
27
+
## 2. Add it to your app module
30
28
Add 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).
31
29
```typescript
32
30
import { PixelModule } from'ngx-pixel';
@@ -46,7 +44,7 @@ export class AppModule { }
46
44
```
47
45
**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()`.
48
46
49
-
###3. Add it to your components
47
+
## 3. Add it to your components
50
48
In any component where you would like to track certain events, you can import the ***ngx-pixel service*** with `import { PixelService } from 'ngx-pixel';`
51
49
Then you can inject the service into your component as follows:
52
50
```TypeScript
@@ -59,10 +57,10 @@ export class HomeComponent {
59
57
}
60
58
```
61
59
62
-
###4. Tracking events
60
+
## 4. Tracking events
63
61
There are two groups of events that you can track, namely *Standard events* and *Custom events*.
64
62
65
-
####Standard events
63
+
### Standard events
66
64
**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:
67
65

Tracking **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:
##Enabling and disabling ***ngx-pixel*** <aname="enabling"></a>
91
+
# Enabling and disabling ***ngx-pixel*** <aname="enabling"></a>
94
92
***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
93
96
-
###Enabling ***ngx-pixel*** immediately
94
+
## Enabling ***ngx-pixel*** immediately
97
95
It is still possible to initialize ***ngx-pixel*** as soon as your app module loads.
98
96
When adding ***ngx-pixel*** to `app.module.ts`, add the parameter `enabled: true`.
99
97
```TypeScript
@@ -103,7 +101,7 @@ imports: [
103
101
],
104
102
```
105
103
106
-
###Enabling ***ngx-pixel*** from a component
104
+
## Enabling ***ngx-pixel*** from a component
107
105
You can also enable ***ngx-pixel*** from within any of your components, like so:
108
106
```TypeScript
109
107
exportclassHomeComponent {
@@ -119,7 +117,7 @@ export class HomeComponent {
119
117
}
120
118
```
121
119
122
-
###Disabling ***ngx-pixel***
120
+
## Disabling ***ngx-pixel***
123
121
Disabling works very similar to *enabling* from within a component and looks like this:
124
122
```TypeScript
125
123
exportclassHomeComponent {
@@ -137,21 +135,19 @@ export class HomeComponent {
137
135
138
136
---
139
137
140
-
##Important notes
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.
138
+
# Important notes
139
+
- 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.
142
140
143
141
---
144
142
145
-
##What's next?
143
+
# What's next?
146
144
-[ ] Checking Pixel ID's using a RegEx. First need to confirm whether all Pixel ID's follow the same format.
147
145
-[ ] Adding tests.
148
146
-[ ] Testing View Engine backwards-compatibility.
149
147
-[ ] Removing all Facebook scripts on removal, not just the initial script.
150
148
151
149
---
152
-
<center>
153
150
Created with ❤️ by Niels Kersic, [niels.codes](https://niels.codes).
0 commit comments