Skip to content

Commit

Permalink
Adding facebook lead tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
calebfavor committed Apr 6, 2017
1 parent aafc8f0 commit eb40270
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @method static string trackInitiateCheckout(array $products, $step, $currency = 'USD')
* @method static string trackAddPaymentInformation()
* @method static string trackTransaction(array $products, $transactionId, $revenue, $tax, $shipping, $currency = 'USD')
* @method static string trackLead($value = null, $currency= 'USD')
* @method static string trackRegistration()
*/
class Tracker
Expand Down
30 changes: 29 additions & 1 deletion src/TrackingProviders/FacebookPixelTrackingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,40 @@ public static function trackTransaction(
<script>
fbq('track', 'Purchase', {
content_ids: ['"
. implode("', '", array_column($products, 'id')) . "'],
. implode("', '", array_column($products, 'id')) . "'],
content_type: 'product',
value: " . number_format($revenue, 2, '.', '') . ",
currency: '" . $currency . "'
});
</script>
";
}

/**
* @param $value
* @param string $currency
*/
public static function trackLead(
$value = null,
$currency = 'USD'
) {
if (is_null($value)) {
self::$bodyTop .=
"
<script>
fbq('track', 'Lead', {});
</script>
";
} else {
self::$bodyTop .=
"
<script>
fbq('track', 'Lead', {
value: " . number_format($value, 2, '.', '') . ",
currency: '" . $currency . "'
});
</script>
";
}
}
}

0 comments on commit eb40270

Please sign in to comment.