summaryrefslogtreecommitdiffstats
path: root/facebook_pixel.api.php
diff options
context:
space:
mode:
Diffstat (limited to 'facebook_pixel.api.php')
-rw-r--r--facebook_pixel.api.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/facebook_pixel.api.php b/facebook_pixel.api.php
new file mode 100644
index 0000000..51a8110
--- /dev/null
+++ b/facebook_pixel.api.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @file
+ * API documentation for Facebook Pixel.
+ */
+
+/**
+ * Alters the final array of data items to be pushed.
+ *
+ * Modules can implement hook_facebook_pixel_data_ACTION_alter() to modify
+ * data sent to Facebook Pixel for a specific action.
+ *
+ * Possible actions:
+ * - Purchase
+ * - AddToCart
+ * - InitiateCheckout
+ * - CompleteRegistration
+ * - ViewContent
+ *
+ * @param array &$$data
+ * By reference. An array of all encoded data elements.
+ *
+ * @param int $entity_id
+ * Associated entity id.
+ */
+function hook_facebook_pixel_data_ACTION_alter(&$data, $order_id) {
+ // Example for 'Purchase' action: Add product ids to the purchase data.
+ $order_wrapper = entity_metadata_wrapper('commerce_order', $order_id);
+
+ $product_ids = array();
+ foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
+ if (in_array($line_item_wrapper->getBundle(), commerce_product_line_item_types())) {
+ $product_ids[] = $line_item_wrapper->commerce_product->product_id->value();
+ }
+ }
+
+ $data += array(
+ 'content_ids' => $product_ids,
+ 'content_type' => 'product',
+ );
+}