Skip to content

Commit 23e6b97

Browse files
committed
fix(refactor): Update README.md
1 parent 129396b commit 23e6b97

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

Diff for: README.md

+27-24
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $ npm install --save-dev @beyonk/svelte-facebook-pixel
2222
## Usage
2323

2424
```html
25-
<FacebookPixel bind:this={fb} id={123} />
25+
<FacebookPixel pixels={[ 'ABC123', '123ABC' ]} />
2626

2727
<script>
2828
import FacebookPixel from '@beyonk/svelte-facebook-pixel'
@@ -37,13 +37,11 @@ Simply call the track mehtod:
3737

3838

3939
```html
40-
<FacebookPixel bind:this={fb} />
40+
<FacebookPixel />
4141

4242
<script>
43-
import FacebookPixel from '@beyonk/svelte-facebook-pixel'
43+
import { FacebookPixel, fb } from '@beyonk/svelte-facebook-pixel'
4444
import { onMount } from 'svelte
45-
46-
let fb
4745
4846
onMount(() => {
4947
fb.track('SomeEvent', { some: 'data' })
@@ -56,23 +54,26 @@ Simply call the track mehtod:
5654
You can have multiple pixels on a page, for instance, if you need a backup pixel, or if you want to send different events to different pixels.
5755
5856
```html
59-
<FacebookPixel bind:this={fb} />
57+
<!-- __layout.svelte -->
58+
<FacebookPixel />
6059
6160
<script>
62-
import FacebookPixel from '@beyonk/svelte-facebook-pixel'
61+
import { FacebookPixel, fb } from '@beyonk/svelte-facebook-pixel'
6362
import { onMount } from 'svelte
64-
65-
let fb
6663
6764
onMount(() => {
6865
fb.track('SomeEvent', { some: 'data' })
6966
})
7067
</script>
7168

72-
<FacebookPixel ref:fb id={['123', '456']} />
69+
<!-- page.svelte -->
7370

7471
<script>
75-
import FacebookPixel from '@beyonk/svelte-facebook-pixel'
72+
import { fb } from '@beyonk/svelte-facebook-pixel'
73+
74+
onMount(() => {
75+
fb.track('AnotherEvent', { some: 'data' })
76+
})
7677
</script>
7778
```
7879

@@ -88,35 +89,37 @@ fb.track('SomeEvent', { some: 'data' })
8889

8990
#### Sending events to a single pixel
9091

91-
If you have multiple pixels on your page and want to send an event to only one of them, specify the pixel's id as the last parameter:
92+
If you have multiple pixels on your page and want to send an event to only one of them use `trackSingle` and pass the pixel's ID as the first argument:
9293

9394
```js
94-
fb.track('SomeEvent', { some: 'data' }, '456')
95+
fb.trackSingle('ABC123', 'SomeEvent', { some: 'data' })
9596
```
9697

9798
## Disabling the pixel (for GDPR)
9899

99100
If you'd like to install the pixel disabled, and enable it later after the user has consented to its use, you can do so by setting `enabled: false` in the pixel configuration:
100101

101102
```html
102-
<FacebookPixel bind:this={fb} enabled={false} />
103+
<FacebookPixel enabled={false} />
103104
```
104105

105106
Now, in your component, you can call the following in order to start the pixel and track the current page.
106107

107-
```js
108-
fb.enable()
109-
```
108+
```html
109+
<FacebookPixel bind:this={_fb} {enabled} />
110110

111-
## Module options
111+
<script>
112+
import { fb } from '@beyonk/svelte-facebook-pixel'
112113
113-
List of possible options in the module:
114+
let _fb = null
115+
let enabled = false
114116
115-
| Option | Default | Required | Description |
116-
|----------|----------|----------|-------------------------------------------------------------------------------------------|
117-
| id | null | true | The unique pixel identifier provided by Facebook. |
118-
| version | v3.1 | false | Tracking version. |
119-
| enabled | true | false | Disable the Pixel by default when initialized. Can be enabled later through `<component>.enable()`. |
117+
onMount(() => {
118+
enabled = true
119+
_fb.init()
120+
})
121+
</script>
122+
```
120123

121124
## License
122125

0 commit comments

Comments
 (0)