From b44d29e4a9cd770822326dd3828ae3f1a57261e1 Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Thu, 20 May 2021 21:09:22 +0200 Subject: [PATCH 01/10] Update package.json Updated package.json to no longer require Angular 11 as a peer dependency --- projects/pixel/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/pixel/package.json b/projects/pixel/package.json index 1c21ce3..4548bcb 100644 --- a/projects/pixel/package.json +++ b/projects/pixel/package.json @@ -13,10 +13,10 @@ "url": "https://github.com/NielsKersic/ngx-pixel" }, "peerDependencies": { - "@angular/common": "^11.0.1", - "@angular/core": "^11.0.1" + "@angular/common": ">=11.0.1", + "@angular/core": ">=11.0.1" }, "dependencies": { - "tslib": "^2.0.0" + "tslib": ">=2.0.0" } } From a268784982a7635ee0a3ba1223e440c17c520200 Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Thu, 20 May 2021 21:13:00 +0200 Subject: [PATCH 02/10] Fix #3 Removed pixel ID length check as these are not always the same length. There is also no documentation which shapes a pixel ID can take. --- projects/pixel/src/lib/pixel.module.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/projects/pixel/src/lib/pixel.module.ts b/projects/pixel/src/lib/pixel.module.ts index 94672a5..ccae5c5 100644 --- a/projects/pixel/src/lib/pixel.module.ts +++ b/projects/pixel/src/lib/pixel.module.ts @@ -41,15 +41,9 @@ export class PixelModule { */ private static verifyPixelId(pixelId: string): void { - // Regular expression for Pixel ID format (15 digits) (not yet implemented) - const regex = /^\d{15}$/; - - // TODO: Check validity of Pixel ID with a RegEx. // Have to verify first that all Pixel IDs follow the same 15 digit format if (pixelId === null || pixelId === undefined || pixelId.length === 0) { throw Error('Invalid Facebook Pixel ID. Did you pass the ID into the forRoot() function?'); - } else if (!regex.test(pixelId)) { - throw Error('Invalid Facebook Pixel ID. The ID should consist of 15 digits.'); } } From 2525cd3b7301eaf3cc2bbaf11425bc5702837d97 Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Thu, 20 May 2021 21:46:53 +0200 Subject: [PATCH 03/10] Update models Moved Pixel event names from inline to models as new type PixelEventName --- projects/pixel/src/lib/pixel.models.ts | 19 +++++++++++++++++++ projects/pixel/src/lib/pixel.service.ts | 22 ++-------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/projects/pixel/src/lib/pixel.models.ts b/projects/pixel/src/lib/pixel.models.ts index 605cc63..4215679 100644 --- a/projects/pixel/src/lib/pixel.models.ts +++ b/projects/pixel/src/lib/pixel.models.ts @@ -79,3 +79,22 @@ export interface PixelEventProperties { 'VEF' | 'VND' | 'ZAR'; } + +export type PixelEventName = 'AddPaymentInfo' | +'AddToCart' | +'AddToWishlist' | +'CompleteRegistration' | +'Contact' | +'CustomizeProduct' | +'Donate' | +'FindLocation' | +'InitiateCheckout' | +'Lead' | +'PageView' | +'Purchase' | +'Schedule' | +'Search' | +'StartTrial' | +'SubmitApplication' | +'Subscribe' | +'ViewContent'; diff --git a/projects/pixel/src/lib/pixel.service.ts b/projects/pixel/src/lib/pixel.service.ts index 8c8133b..585032d 100644 --- a/projects/pixel/src/lib/pixel.service.ts +++ b/projects/pixel/src/lib/pixel.service.ts @@ -1,4 +1,4 @@ -import { PixelConfiguration, PixelEventProperties } from './pixel.models'; +import { PixelEventName, PixelConfiguration, PixelEventProperties } from './pixel.models'; import { Inject, Injectable, Optional } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; import { filter } from 'rxjs/operators'; @@ -51,25 +51,7 @@ export class PixelService { * @param properties Optional properties of the event */ track( - eventName: - 'AddPaymentInfo' | - 'AddToCart' | - 'AddToWishlist' | - 'CompleteRegistration' | - 'Contact' | - 'CustomizeProduct' | - 'Donate' | - 'FindLocation' | - 'InitiateCheckout' | - 'Lead' | - 'PageView' | - 'Purchase' | - 'Schedule' | - 'Search' | - 'StartTrial' | - 'SubmitApplication' | - 'Subscribe' | - 'ViewContent', + eventName: PixelEventName, properties?: PixelEventProperties ): void { From 87aa949715296a62ff4aff194711b6e4f32182bb Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Mon, 24 May 2021 15:20:51 +0200 Subject: [PATCH 04/10] Fix #1 Allow dynamic pixel IDs to be passed to `initialize()`. A default ID should still be provided in module declaration. --- projects/pixel/src/lib/pixel.service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/pixel/src/lib/pixel.service.ts b/projects/pixel/src/lib/pixel.service.ts index 585032d..6dac4ce 100644 --- a/projects/pixel/src/lib/pixel.service.ts +++ b/projects/pixel/src/lib/pixel.service.ts @@ -33,9 +33,13 @@ export class PixelService { * - Adds the script to page's head * - Tracks first page view */ - initialize(): void { + initialize(pixelId = this.config.pixelId): void { + if (this.isLoaded()) { + console.warn('Tried to initialize a Pixel instance while another is already active. Please call `remove()` before initializing a new instance.'); + return; + } this.config.enabled = true; - this.addPixelScript(this.config.pixelId); + this.addPixelScript(pixelId); } /** Remove the Pixel tracking script */ From 8554a5ef5f344482d083f3a5f3c4197c6c830f66 Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Mon, 24 May 2021 15:22:04 +0200 Subject: [PATCH 05/10] Update JSDoc --- projects/pixel/src/lib/pixel.models.ts | 3 ++- projects/pixel/src/lib/pixel.module.ts | 2 +- projects/pixel/src/lib/pixel.service.ts | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/projects/pixel/src/lib/pixel.models.ts b/projects/pixel/src/lib/pixel.models.ts index 4215679..7108c01 100644 --- a/projects/pixel/src/lib/pixel.models.ts +++ b/projects/pixel/src/lib/pixel.models.ts @@ -55,7 +55,8 @@ export interface PixelEventProperties { /** * The currency for the `value` specified. - * @see {@link https://developers.facebook.com/docs/marketing-api/currencies} + * + * See {@link https://developers.facebook.com/docs/marketing-api/currencies Facebook Pixel docs - currency codes} */ currency?: 'AED' | 'ARS' | 'AUD' | diff --git a/projects/pixel/src/lib/pixel.module.ts b/projects/pixel/src/lib/pixel.module.ts index ccae5c5..3dab6c2 100644 --- a/projects/pixel/src/lib/pixel.module.ts +++ b/projects/pixel/src/lib/pixel.module.ts @@ -12,7 +12,7 @@ export class PixelModule { constructor( private pixel: PixelService ) { if (!PixelModule.config) { - throw Error('ngx-pixel not configured correctly'); + throw Error('ngx-pixel not configured correctly. Pass the `pixelId` property to the `forRoot()` function'); } if (PixelModule.config.enabled) { this.pixel.initialize(); diff --git a/projects/pixel/src/lib/pixel.service.ts b/projects/pixel/src/lib/pixel.service.ts index 6dac4ce..62e56e7 100644 --- a/projects/pixel/src/lib/pixel.service.ts +++ b/projects/pixel/src/lib/pixel.service.ts @@ -50,7 +50,8 @@ export class PixelService { /** * Track a Standard Event as predefined by Facebook - * @see {@link https://developers.facebook.com/docs/facebook-pixel/reference} + * + * See {@link https://developers.facebook.com/docs/facebook-pixel/reference Facebook Pixel docs - reference} * @param eventName The name of the event that is being tracked * @param properties Optional properties of the event */ @@ -69,7 +70,8 @@ export class PixelService { /** * Track a custom Event - * @see {@link https://developers.facebook.com/docs/facebook-pixel/implementation/conversion-tracking#custom-conversions} + * + * See {@link https://developers.facebook.com/docs/facebook-pixel/implementation/conversion-tracking#custom-conversions Facebook Pixel docs - custom conversions} * @param eventName The name of the event that is being tracked * @param properties Optional properties of the event */ From fc32cefe21b2d66b67e233e1d414260544b0376e Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Mon, 24 May 2021 20:10:36 +0200 Subject: [PATCH 06/10] Add logging Added console warnings when either of the tracking functions is called without an active Pixel instance --- README.md | 11 ++++++++--- projects/pixel/README.md | 13 ++++++++++--- projects/pixel/src/lib/pixel.module.ts | 6 ++---- projects/pixel/src/lib/pixel.service.ts | 9 +++++++++ tsconfig.json | 2 +- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a4bf3e5..40fdb06 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ import { PixelModule } from 'ngx-pixel'; ], imports: [ BrowserModule, - PixelModule.forRoot({ enabled: true, pixelId: 'YOUR_PIXEL_ID'}) + PixelModule.forRoot({ enabled: true, pixelId: 'YOUR_PIXEL_ID' }) ], providers: [], bootstrap: [AppComponent] @@ -117,6 +117,12 @@ export class HomeComponent { } ``` +## Enabling with a dynamic Pixel ID +In 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. +**Notes:** +- A Pixel ID still needs to be provided when importing ***ngx-pixel*** in the module. +- The previous instance should be removed with `remove()` before initializing a new Pixel ID. + ## Disabling ***ngx-pixel*** Disabling works very similar to *enabling* from within a component and looks like this: ```TypeScript @@ -141,9 +147,8 @@ export class HomeComponent { --- # What's next? -- [ ] Checking Pixel ID's using a RegEx. First need to confirm whether all Pixel ID's follow the same format. +- [ ] Adding Angular Universal SSR support. - [ ] Adding tests. -- [ ] Testing View Engine backwards-compatibility. - [ ] Removing all Facebook scripts on removal, not just the initial script. --- diff --git a/projects/pixel/README.md b/projects/pixel/README.md index 064405b..40fdb06 100644 --- a/projects/pixel/README.md +++ b/projects/pixel/README.md @@ -35,7 +35,7 @@ import { PixelModule } from 'ngx-pixel'; ], imports: [ BrowserModule, - PixelModule.forRoot({ enabled: true, pixelId: 'YOUR_PIXEL_ID'}) + PixelModule.forRoot({ enabled: true, pixelId: 'YOUR_PIXEL_ID' }) ], providers: [], bootstrap: [AppComponent] @@ -117,6 +117,12 @@ export class HomeComponent { } ``` +## Enabling with a dynamic Pixel ID +In 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. +**Notes:** +- A Pixel ID still needs to be provided when importing ***ngx-pixel*** in the module. +- The previous instance should be removed with `remove()` before initializing a new Pixel ID. + ## Disabling ***ngx-pixel*** Disabling works very similar to *enabling* from within a component and looks like this: ```TypeScript @@ -141,12 +147,12 @@ export class HomeComponent { --- # What's next? -- [ ] Checking Pixel ID's using a RegEx. First need to confirm whether all Pixel ID's follow the same format. +- [ ] Adding Angular Universal SSR support. - [ ] Adding tests. -- [ ] Testing View Engine backwards-compatibility. - [ ] Removing all Facebook scripts on removal, not just the initial script. --- + Created with ❤️ by Niels Kersic, [niels.codes](https://niels.codes). @@ -154,3 +160,4 @@ Created with ❤️ by Niels Kersic, [niels.codes](https://niels.codes). + diff --git a/projects/pixel/src/lib/pixel.module.ts b/projects/pixel/src/lib/pixel.module.ts index 3dab6c2..f07f35c 100644 --- a/projects/pixel/src/lib/pixel.module.ts +++ b/projects/pixel/src/lib/pixel.module.ts @@ -3,8 +3,7 @@ import { ModuleWithProviders, NgModule } from '@angular/core'; import { PixelService } from './pixel.service'; @NgModule({ - imports: [ - ], + imports: [], }) export class PixelModule { @@ -21,6 +20,7 @@ export class PixelModule { /** * Initiale the Facebook Pixel Module + * * Add your Pixel ID as parameter */ static forRoot(config: PixelConfiguration): ModuleWithProviders { @@ -40,12 +40,10 @@ export class PixelModule { * @param pixelId Pixel ID to verify */ private static verifyPixelId(pixelId: string): void { - // Have to verify first that all Pixel IDs follow the same 15 digit format if (pixelId === null || pixelId === undefined || pixelId.length === 0) { throw Error('Invalid Facebook Pixel ID. Did you pass the ID into the forRoot() function?'); } - } } diff --git a/projects/pixel/src/lib/pixel.service.ts b/projects/pixel/src/lib/pixel.service.ts index 62e56e7..08218ee 100644 --- a/projects/pixel/src/lib/pixel.service.ts +++ b/projects/pixel/src/lib/pixel.service.ts @@ -59,6 +59,10 @@ export class PixelService { eventName: PixelEventName, properties?: PixelEventProperties ): void { + if(!this.isLoaded()) { + console.warn('Tried to track an event without initializing a Pixel instance. Call `initialize()` first.'); + return; + } if (properties) { fbq('track', eventName, properties); @@ -76,6 +80,11 @@ export class PixelService { * @param properties Optional properties of the event */ trackCustom(eventName: string, properties?: object): void { + if(!this.isLoaded()) { + console.warn('Tried to track an event without initializing a Pixel instance. Call `initialize()` first.'); + return; + } + if (properties) { fbq('trackCustom', eventName, properties); } else { diff --git a/tsconfig.json b/tsconfig.json index 29bba46..7bb287a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -31,4 +31,4 @@ "strictInputAccessModifiers": true, "strictTemplates": true } -} \ No newline at end of file +} From c59fad85d1208ec747635b2fd7d61be0c410ac04 Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Mon, 24 May 2021 20:16:43 +0200 Subject: [PATCH 07/10] Update package.json --- projects/pixel/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/pixel/package.json b/projects/pixel/package.json index 4548bcb..e1de42c 100644 --- a/projects/pixel/package.json +++ b/projects/pixel/package.json @@ -7,7 +7,7 @@ "url": "https://niels.codes" }, "license": "MIT", - "version": "1.0.0", + "version": "1.0.2", "repository": { "type": "git", "url": "https://github.com/NielsKersic/ngx-pixel" From e9a1219b5af72169b122b40edaad4a821bc844c1 Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Thu, 27 May 2021 13:30:08 +0200 Subject: [PATCH 08/10] Fix #2 Added support for serverside rendering with Angular Universal Replaced document calls with renderer2 or an injected DOCUMENT --- projects/pixel/src/lib/pixel.module.ts | 10 +++-- projects/pixel/src/lib/pixel.service.ts | 60 ++++++++++++++++++------- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/projects/pixel/src/lib/pixel.module.ts b/projects/pixel/src/lib/pixel.module.ts index f07f35c..7334b99 100644 --- a/projects/pixel/src/lib/pixel.module.ts +++ b/projects/pixel/src/lib/pixel.module.ts @@ -1,5 +1,6 @@ import { PixelConfiguration } from './pixel.models'; -import { ModuleWithProviders, NgModule } from '@angular/core'; +import { Inject, ModuleWithProviders, NgModule, PLATFORM_ID } from '@angular/core'; +import { isPlatformBrowser } from '@angular/common'; import { PixelService } from './pixel.service'; @NgModule({ @@ -9,11 +10,14 @@ export class PixelModule { private static config: PixelConfiguration | null = null; - constructor( private pixel: PixelService ) { + constructor( + private pixel: PixelService, + @Inject(PLATFORM_ID) platformId: Object + ) { if (!PixelModule.config) { throw Error('ngx-pixel not configured correctly. Pass the `pixelId` property to the `forRoot()` function'); } - if (PixelModule.config.enabled) { + if (PixelModule.config.enabled && isPlatformBrowser(platformId)) { this.pixel.initialize(); } } diff --git a/projects/pixel/src/lib/pixel.service.ts b/projects/pixel/src/lib/pixel.service.ts index 08218ee..4a5c572 100644 --- a/projects/pixel/src/lib/pixel.service.ts +++ b/projects/pixel/src/lib/pixel.service.ts @@ -1,20 +1,32 @@ import { PixelEventName, PixelConfiguration, PixelEventProperties } from './pixel.models'; -import { Inject, Injectable, Optional } from '@angular/core'; +import { Inject, Injectable, Optional, PLATFORM_ID, Renderer2, RendererFactory2 } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; +import { DOCUMENT, isPlatformBrowser } from '@angular/common'; import { filter } from 'rxjs/operators'; -declare var fbq: any; +declare const fbq: any; @Injectable({ providedIn: 'root' }) export class PixelService { + private doc: Document; + private renderer: Renderer2 + constructor( @Inject('config') private config: PixelConfiguration, - @Optional() private router: Router + @Inject(DOCUMENT) private injectedDocument: any, + @Inject(PLATFORM_ID) private platformId: Object, + @Optional() private router: Router, + private rendererFactory: RendererFactory2 ) { + // DOCUMENT cannot be injected directly as Document type, see https://github.com/angular/angular/issues/20351 + // It is therefore injected as any and then cast to Document + this.doc = injectedDocument as Document; + this.renderer = rendererFactory.createRenderer(null, null); + if (router) { // Log page views after router navigation ends router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(event => { @@ -33,7 +45,7 @@ export class PixelService { * - Adds the script to page's head * - Tracks first page view */ - initialize(pixelId = this.config.pixelId): void { + initialize(pixelId?: string): void { if (this.isLoaded()) { console.warn('Tried to initialize a Pixel instance while another is already active. Please call `remove()` before initializing a new instance.'); return; @@ -58,8 +70,12 @@ export class PixelService { track( eventName: PixelEventName, properties?: PixelEventProperties - ): void { - if(!this.isLoaded()) { + ): void { + if (!isPlatformBrowser(this.platformId)) { + return; + } + + if (!this.isLoaded()) { console.warn('Tried to track an event without initializing a Pixel instance. Call `initialize()` first.'); return; } @@ -80,7 +96,11 @@ export class PixelService { * @param properties Optional properties of the event */ trackCustom(eventName: string, properties?: object): void { - if(!this.isLoaded()) { + if (!isPlatformBrowser(this.platformId)) { + return; + } + + if (!this.isLoaded()) { console.warn('Tried to track an event without initializing a Pixel instance. Call `initialize()` first.'); return; } @@ -97,6 +117,9 @@ export class PixelService { * @param pixelId The Facebook Pixel ID to use */ private addPixelScript(pixelId: string): void { + if (!isPlatformBrowser(this.platformId)) { + return; + } const pixelCode = ` var pixelCode = function(f,b,e,v,n,t,s) @@ -110,16 +133,20 @@ export class PixelService { fbq('init', '${pixelId}'); fbq('track', 'PageView');`; - const scriptElement = document.createElement('script'); - scriptElement.setAttribute('id', 'pixel-script'); - scriptElement.type = 'text/javascript'; - scriptElement.innerHTML = pixelCode; - document.getElementsByTagName('head')[0].appendChild(scriptElement); + + const scriptElement = this.renderer.createElement('script'); + this.renderer.setAttribute(scriptElement, 'id', 'pixel-script'); + this.renderer.setAttribute(scriptElement, 'type', 'text/javascript'); + this.renderer.setProperty(scriptElement, 'innerHTML', pixelCode); + this.renderer.appendChild(this.doc.head, scriptElement); } /** Remove Facebook Pixel tracking script from the application */ private removePixelScript(): void { - const pixelElement = document.getElementById('pixel-script'); + if (!isPlatformBrowser(this.platformId)) { + return; + } + const pixelElement = this.doc.getElementById('pixel-script'); if (pixelElement) { pixelElement.remove(); } @@ -127,8 +154,11 @@ export class PixelService { /** Checks if the script element is present */ private isLoaded(): boolean { - const pixelElement = document.getElementById('pixel-script'); - return !!pixelElement; + if (isPlatformBrowser(this.platformId)) { + const pixelElement = this.doc.getElementById('pixel-script'); + return !!pixelElement; + } + return false; } } From a975963f4793f82c2d75742de1e8c8e1132c5976 Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Thu, 27 May 2021 13:32:41 +0200 Subject: [PATCH 09/10] Update docs and package.json Updated docs and package.json to reflect added SSR functionality --- README.md | 5 +++-- projects/pixel/README.md | 5 +++-- projects/pixel/package.json | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 40fdb06..1cc89b9 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,8 @@ export class HomeComponent { In 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. **Notes:** - A Pixel ID still needs to be provided when importing ***ngx-pixel*** in the module. -- The previous instance should be removed with `remove()` before initializing a new Pixel ID. +- The previous instance should be removed with `remove()` before initializing a new Pixel ID. +- 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. ## Disabling ***ngx-pixel*** Disabling works very similar to *enabling* from within a component and looks like this: @@ -147,7 +148,7 @@ export class HomeComponent { --- # What's next? -- [ ] Adding Angular Universal SSR support. +- [X] Adding Angular Universal SSR support. - [ ] Adding tests. - [ ] Removing all Facebook scripts on removal, not just the initial script. diff --git a/projects/pixel/README.md b/projects/pixel/README.md index 40fdb06..1cc89b9 100644 --- a/projects/pixel/README.md +++ b/projects/pixel/README.md @@ -121,7 +121,8 @@ export class HomeComponent { In 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. **Notes:** - A Pixel ID still needs to be provided when importing ***ngx-pixel*** in the module. -- The previous instance should be removed with `remove()` before initializing a new Pixel ID. +- The previous instance should be removed with `remove()` before initializing a new Pixel ID. +- 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. ## Disabling ***ngx-pixel*** Disabling works very similar to *enabling* from within a component and looks like this: @@ -147,7 +148,7 @@ export class HomeComponent { --- # What's next? -- [ ] Adding Angular Universal SSR support. +- [X] Adding Angular Universal SSR support. - [ ] Adding tests. - [ ] Removing all Facebook scripts on removal, not just the initial script. diff --git a/projects/pixel/package.json b/projects/pixel/package.json index e1de42c..357b428 100644 --- a/projects/pixel/package.json +++ b/projects/pixel/package.json @@ -7,7 +7,7 @@ "url": "https://niels.codes" }, "license": "MIT", - "version": "1.0.2", + "version": "1.1.0", "repository": { "type": "git", "url": "https://github.com/NielsKersic/ngx-pixel" From 27662a0c2bbd18769ee73b51a8a4b2a3084d4df1 Mon Sep 17 00:00:00 2001 From: Niels Kersic Date: Thu, 27 May 2021 13:42:36 +0200 Subject: [PATCH 10/10] Fix: mistake in auto assigning Pixel ID from config --- projects/pixel/src/lib/pixel.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/pixel/src/lib/pixel.service.ts b/projects/pixel/src/lib/pixel.service.ts index 4a5c572..a85b4d5 100644 --- a/projects/pixel/src/lib/pixel.service.ts +++ b/projects/pixel/src/lib/pixel.service.ts @@ -45,7 +45,7 @@ export class PixelService { * - Adds the script to page's head * - Tracks first page view */ - initialize(pixelId?: string): void { + initialize(pixelId = this.config.pixelId): void { if (this.isLoaded()) { console.warn('Tried to initialize a Pixel instance while another is already active. Please call `remove()` before initializing a new instance.'); return;