Skip to content

Commit 44e9236

Browse files
committed
Fixing FB Pixel
1 parent 91ca325 commit 44e9236

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

mu-facebook-pixel/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010

1111
### `FBP_DISABLE`
1212

13-
Disables the tracking code. Define it as `true` in `wp-config`
13+
Disables the tracking code.
14+
Define it as `true` in `wp-config`.
15+
By default the tracking code is enabled.
1416

1517
### `FBP_FACEBOOK_RECOMMENDATION`
1618

17-
Inserts the tracking code before the ending `</head>` tag. Defaults is before the closing `</body>` tag.
19+
Inserts the tracking code before the ending `</head>` tag.
20+
Define it as `true` in `wp-config`.
21+
Default is before the closing `</body>` tag.
1822

1923
## Filters
2024

@@ -24,7 +28,7 @@ Disable for users with this capability. Defaults to `edit_pages`
2428

2529
### `fbp_extra_javascript`
2630

27-
Add extra JavaScript code before `fbq('track', "PageView");`. Defaults to an empty string.
31+
Track custom event instead of page view. Defaults to `fbq('track', 'PageView');`.
2832

2933
## Examples
3034

@@ -33,9 +37,9 @@ Adding extra JavaScript.
3337
```php
3438
// Analytics.js Field Reference
3539
// https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference
36-
add_filter( 'gua_extra_javascript', function ( $js ) {
37-
$js .= "ga('set', 'anonymizeIp', true);\n";
38-
$js .= "ga('set', 'forceSSL', true);\n";
40+
add_filter( 'fbp_extra_javascript', function ( $js ) {
41+
42+
$js = sprintf( "fbq('track', 'Purchase', {currency: 'EUR', value: %.2f});", $cart_total );
3943

4044
return $js;
4145
});
@@ -44,7 +48,7 @@ add_filter( 'gua_extra_javascript', function ( $js ) {
4448
Adding a Dynamic Event.
4549

4650
```js
47-
( typeof fbq === 'function' ) && fbq('track', 'Lead' {
51+
( typeof fbq === 'function' ) && fbq('track', 'Lead' {
4852
content_name: 'Main Contact Form submit',
4953
referrer: document.referrer,
5054
userAgent: navigator.userAgent,
@@ -54,6 +58,6 @@ Adding a Dynamic Event.
5458

5559
## Remarks
5660

57-
58-
5961
On development sites the tracking code is not enabled, when `WP_ENV` is not `production`.
62+
63+
[API Reference](https://developers.facebook.com/docs/facebook-pixel/api-reference)

mu-facebook-pixel/facebook-pixel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ final class FBP {
2222
document,'script','//connect.facebook.net/%s/fbevents.js');
2323
fbq('init', '%s');
2424
%s
25-
fbq('track', 'PageView');
2625
</script>
2726
<noscript><img height='1' width='1' style='display:none'
2827
src='https://www.facebook.com/tr?id=%s&amp;ev=PageView&amp;noscript=1'
@@ -93,7 +92,7 @@ public function init() {
9392
$this->snippet = sprintf( $this->snippet_template,
9493
$lang,
9594
$pid,
96-
apply_filters( 'fbp_extra_javascript', '' ),
95+
apply_filters( 'fbp_extra_javascript', "fbq('track', 'PageView');" ),
9796
$pid
9897
);
9998

0 commit comments

Comments
 (0)