Skip to content

Commit 87aa949

Browse files
committed
Fix #1
Allow dynamic pixel IDs to be passed to `initialize()`. A default ID should still be provided in module declaration.
1 parent 2525cd3 commit 87aa949

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

projects/pixel/src/lib/pixel.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ export class PixelService {
3333
* - Adds the script to page's head
3434
* - Tracks first page view
3535
*/
36-
initialize(): void {
36+
initialize(pixelId = this.config.pixelId): void {
37+
if (this.isLoaded()) {
38+
console.warn('Tried to initialize a Pixel instance while another is already active. Please call `remove()` before initializing a new instance.');
39+
return;
40+
}
3741
this.config.enabled = true;
38-
this.addPixelScript(this.config.pixelId);
42+
this.addPixelScript(pixelId);
3943
}
4044

4145
/** Remove the Pixel tracking script */

0 commit comments

Comments
 (0)