Skip to content

Commit

Permalink
Add user data to pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola Pavlovic committed Dec 12, 2024
1 parent 694d482 commit 8c4d657
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions core/class-pixelrenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,30 @@ private static function get_pixel_track_code(
$event->getCustomData() : new CustomData();

$normalized_custom_data = $custom_data->normalize();
if ( ! is_null( $fb_integration_tracking ) ) {
$normalized_custom_data[ self::FB_INTEGRATION_TRACKING ] =
$fb_integration_tracking;
}
if ( ! is_null( $fb_integration_tracking ) ) {
$normalized_custom_data[ self::FB_INTEGRATION_TRACKING ] =
$fb_integration_tracking;
}

$user_data = $event->getUserData();
$normalized_user_data = $user_data->normalize();
$normalized_data = array_merge(
$normalized_custom_data,
$normalized_user_data
);

$class = new ReflectionClass(
'FacebookPixelPlugin\Core\FacebookPixel'
);
return sprintf(
self::FBQ_EVENT_CODE,
$class->getConstant( strtoupper( $event->getEventName() ) ) !== false ?
self::TRACK : self::TRACK_CUSTOM,
$event->getEventName(),
wp_json_encode( $normalized_custom_data, JSON_PRETTY_PRINT ),
wp_json_encode( $event_data, JSON_PRETTY_PRINT )
);

return sprintf(
self::FBQ_EVENT_CODE,
$class->getConstant( strtoupper( $event->getEventName() ) ) !==
false ?
self::TRACK : self::TRACK_CUSTOM,
$event->getEventName(),
wp_json_encode( $normalized_data, JSON_PRETTY_PRINT ),
wp_json_encode( $event_data, JSON_PRETTY_PRINT )
);
}
}

0 comments on commit 8c4d657

Please sign in to comment.