Skip to content

Commit

Permalink
Tweak build class mapping (#65)
Browse files Browse the repository at this point in the history
Summary:
This changeset includes the following updates:
- Tweak class mapping during the build process to ensure compatibility,
- Tweak the code style, and
- Update admin section panel showing/hiding depending on the connection to MBE being established or not.

Pull Request resolved: #65

Reviewed By: akpurifb

Differential Revision: D67334429

Pulled By: vahidkay-meta

fbshipit-source-id: d2bee8e28153496144cbadb23be2f7dca7531ffd
  • Loading branch information
iodic authored and facebook-github-bot committed Dec 17, 2024
1 parent 10ce527 commit 583009c
Show file tree
Hide file tree
Showing 24 changed files with 1,813 additions and 1,802 deletions.
10 changes: 1 addition & 9 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
<exclude name="vendor/**" />
<exclude name="task/**" />
<exclude name="__tests__/**" />
<exclude name="js/**" />
</fileset>

<!-- Fileset for all built JS files -->
<fileset dir="${basedir}" id="all-fbe-js">
<include name="js/fbe_allinone.js" />
<exclude name="js/lib/**" />
</fileset>

<!-- Fileset for files using GuzzleHttp-->
Expand Down Expand Up @@ -54,9 +49,6 @@
<copy todir="${buildsourcedir}">
<fileset refid="sourcedir" />
</copy>
<copy todir="${buildsourcedir}">
<fileset refid="all-fbe-js" />
</copy>
<echo msg="Copy complete" />
<echo msg="Run compose install..." />
<composer command="install">
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"FacebookPixelPlugin\\": "./",
"FacebookPixelPlugin\\Core\\": "core/",
"FacebookPixelPlugin\\Integration\\": "integration/"
}
},
"classmap": [
"./"
]
},
"autoload-dev": {
"classmap": [
Expand Down
24 changes: 12 additions & 12 deletions core/class-facebookcapievent.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ public function send_capi_event() {
public function get_invalid_event_custom_data( $custom_data ) {
$invalid_custom_data = array();
foreach ( $custom_data as $key => $value ) {
if ( ! in_array( $key, self::VALID_CUSTOM_DATA, true ) ) {
array_push( $invalid_custom_data, $key );
}
if ( ! in_array( $key, self::VALID_CUSTOM_DATA, true ) ) {
array_push( $invalid_custom_data, $key );
}
}
return $invalid_custom_data;
}
Expand Down Expand Up @@ -293,15 +293,15 @@ public function validate_payload( $payload ) {
foreach ( $payload['data'] as $event ) {
foreach ( self::REQUIRED_EVENT_DATA as $attribute ) {
if ( ! array_key_exists( $attribute, $event ) ) {
if ( ! empty( $response['message'] ) ) {
$response['error_user_msg'] .=
", {$attribute} attribute is missing";
} else {
$response['valid'] = false;
$response['message'] = 'Missing required attribute';
$response['error_user_msg'] =
"{$attribute} attribute is missing";
}
if ( ! empty( $response['message'] ) ) {
$response['error_user_msg'] .=
", {$attribute} attribute is missing";
} else {
$response['valid'] = false;
$response['message'] = 'Missing required attribute';
$response['error_user_msg'] =
"{$attribute} attribute is missing";
}
}
}

Expand Down
188 changes: 94 additions & 94 deletions core/class-facebookpixel.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ public static function get_pixel_base_code() {
* Gets OpenBridge set config code
*/
public static function get_open_bridge_config_code() {
if ( empty( self::$pixel_id ) ) {
return;
}
if ( empty( self::$pixel_id ) ) {
return;
}

$code = "
<script type='text/javascript'>
var url = window.location.origin + '?ob=open-bridge';
fbq('set', 'openbridge', '%s', url);
</script>
";
<script type='text/javascript'>
var url = window.location.origin + '?ob=open-bridge';
fbq('set', 'openbridge', '%s', url);
</script>
";
return sprintf( $code, self::$pixel_id );
}

Expand All @@ -169,30 +169,30 @@ public static function get_pixel_init_code(
$param = array(),
$with_script_tag = true
) {
if ( empty( self::$pixel_id ) ) {
return;
}
if ( empty( self::$pixel_id ) ) {
return;
}

$pixel_fbq_code_without_script = "fbq('%s', '%s'%s%s)";

$code = $with_script_tag ? "<script type='text/javascript'>" .
$pixel_fbq_code_without_script .
'</script>' : $pixel_fbq_code_without_script;
$param_str = $param;
if ( is_array( $param ) ) {
$param_str = wp_json_encode(
$param,
JSON_PRETTY_PRINT | JSON_FORCE_OBJECT
);
}
if ( is_array( $param ) ) {
$param_str = wp_json_encode(
$param,
JSON_PRETTY_PRINT | JSON_FORCE_OBJECT
);
}
$agent_param = array( 'agent' => $agent_string );
return sprintf(
$code,
'init',
self::$pixel_id,
', ' . $param_str,
', ' . wp_json_encode( $agent_param, JSON_PRETTY_PRINT )
);
return sprintf(
$code,
'init',
self::$pixel_id,
', ' . $param_str,
', ' . wp_json_encode( $agent_param, JSON_PRETTY_PRINT )
);
}

/**
Expand All @@ -217,30 +217,30 @@ public static function get_pixel_track_code(
$tracking_name = '',
$with_script_tag = true
) {
if ( empty( self::$pixel_id ) ) {
return;
}
if ( empty( self::$pixel_id ) ) {
return;
}

$code = $with_script_tag ? "<script type='text/javascript'>" .
self::$pixel_fbq_code_without_script .
'</script>' : self::$pixel_fbq_code_without_script;
$param_str = $param;
if ( is_array( $param ) ) {
if ( ! empty( $tracking_name ) ) {
$param[ self::FB_INTEGRATION_TRACKING_KEY ] = $tracking_name;
if ( is_array( $param ) ) {
if ( ! empty( $tracking_name ) ) {
$param[ self::FB_INTEGRATION_TRACKING_KEY ] = $tracking_name;
}
$param_str = wp_json_encode( $param, JSON_PRETTY_PRINT );
}
$param_str = wp_json_encode( $param, JSON_PRETTY_PRINT );
}
$class = new ReflectionClass( __CLASS__ );
return sprintf(
$code,
$class->getConstant(
strtoupper( $event )
) !== false ? 'track' : 'trackCustom',
$event,
', ' . $param_str,
''
);
return sprintf(
$code,
$class->getConstant(
strtoupper( $event )
) !== false ? 'track' : 'trackCustom',
$event,
', ' . $param_str,
''
);
}

/**
Expand All @@ -255,24 +255,24 @@ public static function get_pixel_noscript_code(
$cd = array(),
$tracking_name = ''
) {
if ( empty( self::$pixel_id ) ) {
return;
}
if ( empty( self::$pixel_id ) ) {
return;
}

$data = '';
foreach ( $cd as $k => $v ) {
$data .= '&cd[' . $k . ']=' . $v;
}
if ( ! empty( $tracking_name ) ) {
$data .= '&cd[' . self::FB_INTEGRATION_TRACKING_KEY . ']=' .
$tracking_name;
}
return sprintf(
self::$pixel_noscript_code,
self::$pixel_id,
$event,
$data
);
$data = '';
foreach ( $cd as $k => $v ) {
$data .= '&cd[' . $k . ']=' . $v;
}
if ( ! empty( $tracking_name ) ) {
$data .= '&cd[' . self::FB_INTEGRATION_TRACKING_KEY . ']=' .
$tracking_name;
}
return sprintf(
self::$pixel_noscript_code,
self::$pixel_id,
$event,
$data
);
}

/**
Expand All @@ -288,12 +288,12 @@ public static function get_pixel_add_to_cart_code(
$tracking_name = '',
$with_script_tag = true
) {
return self::get_pixel_track_code(
self::ADDTOCART,
$param,
$tracking_name,
$with_script_tag
);
return self::get_pixel_track_code(
self::ADDTOCART,
$param,
$tracking_name,
$with_script_tag
);
}

/**
Expand All @@ -309,12 +309,12 @@ public static function get_pixel_initiate_checkout_code(
$tracking_name = '',
$with_script_tag = true
) {
return self::get_pixel_track_code(
self::INITIATECHECKOUT,
$param,
$tracking_name,
$with_script_tag
);
return self::get_pixel_track_code(
self::INITIATECHECKOUT,
$param,
$tracking_name,
$with_script_tag
);
}

/**
Expand All @@ -330,12 +330,12 @@ public static function get_pixel_lead_code(
$tracking_name = '',
$with_script_tag = true
) {
return self::get_pixel_track_code(
self::LEAD,
$param,
$tracking_name,
$with_script_tag
);
return self::get_pixel_track_code(
self::LEAD,
$param,
$tracking_name,
$with_script_tag
);
}

/**
Expand All @@ -351,12 +351,12 @@ public static function get_pixel_page_view_code(
$tracking_name = '',
$with_script_tag = true
) {
return self::get_pixel_track_code(
self::PAGEVIEW,
$param,
$tracking_name,
$with_script_tag
);
return self::get_pixel_track_code(
self::PAGEVIEW,
$param,
$tracking_name,
$with_script_tag
);
}

/**
Expand All @@ -372,12 +372,12 @@ public static function get_pixel_purchase_code(
$tracking_name = '',
$with_script_tag = true
) {
return self::get_pixel_track_code(
self::PURCHASE,
$param,
$tracking_name,
$with_script_tag
);
return self::get_pixel_track_code(
self::PURCHASE,
$param,
$tracking_name,
$with_script_tag
);
}

/**
Expand All @@ -393,11 +393,11 @@ public static function get_pixel_view_content_code(
$tracking_name = '',
$with_script_tag = true
) {
return self::get_pixel_track_code(
self::VIEWCONTENT,
$param,
$tracking_name,
$with_script_tag
);
return self::get_pixel_track_code(
self::VIEWCONTENT,
$param,
$tracking_name,
$with_script_tag
);
}
}
Loading

0 comments on commit 583009c

Please sign in to comment.