PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / WooCommerce_Referrer_Meta_Box.php
independent-analytics / IAWP Last commit date
AJAX 2 years ago Admin_Page 2 years ago Date_Range 2 years ago Interval 2 years ago Menu_Bar_Stats 2 years ago Migrations 2 years ago Models 2 years ago Public_API 2 years ago Rows 2 years ago Statistics 2 years ago Tables 2 years ago Utils 2 years ago Campaign_Builder.php 2 years ago Capability_Manager.php 2 years ago Chart.php 2 years ago Chart_Geo.php 2 years ago Cron_Manager.php 2 years ago Current_Traffic_Finder.php 2 years ago Dashboard_Options.php 2 years ago Dashboard_Widget.php 2 years ago Database_Manager.php 2 years ago Email_Chart.php 2 years ago Email_Reports.php 2 years ago Empty_Report_Option.php 2 years ago Env.php 2 years ago Filters.php 2 years ago Geo_Database_Background_Job.php 2 years ago Geo_Database_Manager.php 2 years ago Geoposition.php 2 years ago Icon_Directory.php 2 years ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 2 years ago Independent_Analytics.php 2 years ago Interrupt.php 2 years ago Known_Referrers.php 2 years ago Plugin_Conflict_Detector.php 2 years ago Query.php 2 years ago Quick_Stats.php 2 years ago REST_API.php 2 years ago Real_Time.php 2 years ago Report.php 2 years ago Report_Finder.php 2 years ago Report_Options_Parser.php 2 years ago Resource_Identifier.php 2 years ago Settings.php 2 years ago Sort_Configuration.php 2 years ago Track_Resource_Changes.php 2 years ago View.php 2 years ago View_Counter.php 2 years ago Visitors_Over_Time_Finder.php 2 years ago WP_Option_Cache_Bust.php 2 years ago WooCommerce_Order.php 2 years ago WooCommerce_Referrer_Meta_Box.php 2 years ago
WooCommerce_Referrer_Meta_Box.php
93 lines
1 <?php
2
3 namespace IAWP_SCOPED\IAWP;
4
5 use IAWP_SCOPED\IAWP\Models\Campaign;
6 use IAWP_SCOPED\IAWP\Models\Referrer;
7 use IAWP_SCOPED\IAWP\Utils\Security;
8 use IAWP_SCOPED\Illuminate\Database\Query\JoinClause;
9 /** @internal */
10 class WooCommerce_Referrer_Meta_Box
11 {
12 public function __construct()
13 {
14 \add_action('add_meta_boxes_shop_order', [$this, 'maybe_add_meta_box'], 10, 1);
15 }
16 public function maybe_add_meta_box(\WP_Post $post) : void
17 {
18 if (\is_null($this->get_referrer_for($post))) {
19 return;
20 }
21 \add_meta_box('iawp-wc-referrer-source', \esc_html__('Order Referrer', 'independent-analytics'), [$this, 'render_meta_box_content'], 'shop_order', 'side');
22 }
23 public function render_meta_box_content(\WP_Post $post) : void
24 {
25 $referrer_row = $this->get_referrer_for($post);
26 $campaign_row = $this->get_campaign_for($post);
27 $referrer_row->referrer_ids = !\is_null($referrer_row->referrer_id) ? [$referrer_row->referrer_id] : null;
28 $referrer = new Referrer($referrer_row);
29 $campaign = new Campaign($campaign_row);
30 if ($referrer->has_link()) {
31 $content = '<a target="_blank" href="' . \esc_url($referrer->referrer_url()) . '">' . Security::string($referrer->referrer()) . '</a>';
32 } else {
33 $content = Security::string($referrer->referrer());
34 }
35 echo '<p><strong>' . \esc_html__('Referrer:', 'independent-analytics') . '</strong> <span data-testid="referrer">' . $content . '</span> <a class="info-link"
36 href="https://independentwp.com/knowledgebase/woocommerce/order-referrers-box/"
37 target="_blank"
38 style="text-decoration:none;float:right;">
39 <span class="dashicons dashicons-editor-help"></span>
40 </a>
41 </p>';
42 if (\is_string($campaign->utm_source())) {
43 echo '<p><strong>' . \__('Campaign Source', 'independent-analytics') . ':</strong> <span data-testid="source">' . Security::string($campaign->utm_source()) . '</span> </p>';
44 }
45 if (\is_string($campaign->utm_medium())) {
46 echo '<p><strong>' . \__('Campaign Medium', 'independent-analytics') . ':</strong> <span data-testid="medium">' . Security::string($campaign->utm_medium()) . '</span> </p>';
47 }
48 if (\is_string($campaign->utm_campaign())) {
49 echo '<p><strong>' . \__('Campaign Name', 'independent-analytics') . ':</strong> <span data-testid="campaign">' . Security::string($campaign->utm_campaign()) . '</span> </p>';
50 }
51 if (\is_string($campaign->utm_term())) {
52 echo '<p><strong>' . \__('Campaign Term', 'independent-analytics') . ':</strong> <span data-testid="term">' . Security::string($campaign->utm_term()) . '</span> </p>';
53 }
54 if (\is_string($campaign->utm_content())) {
55 echo '<p><strong>' . \__('Campaign Content', 'independent-analytics') . ':</strong> <span data-testid="content">' . Security::string($campaign->utm_content()) . '</span> </p>';
56 }
57 }
58 private function get_campaign_for(\WP_Post $post) : ?object
59 {
60 $wc_orders_table = Query::get_table_name(Query::WC_ORDERS);
61 $campaigns_table = Query::get_table_name(Query::CAMPAIGNS);
62 $views_table = Query::get_table_name(Query::VIEWS);
63 $sessions_table = Query::get_table_name(Query::SESSIONS);
64 $referrer_query = Illuminate_Builder::get_builder();
65 $referrer_query->select("landing_page_title AS title", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content")->from($wc_orders_table, 'orders')->leftJoin("{$views_table} AS views", function (JoinClause $join) {
66 $join->on('views.id', '=', 'orders.view_id');
67 })->leftJoin("{$sessions_table} AS sessions", function (JoinClause $join) {
68 $join->on('sessions.session_id', '=', 'views.session_id');
69 })->leftJoin("{$campaigns_table} AS campaigns", function (JoinClause $join) {
70 $join->on('sessions.campaign_id', '=', 'campaigns.campaign_id');
71 })->where('orders.order_id', '=', $post->ID);
72 $record = $referrer_query->get()->first();
73 return $record;
74 }
75 private function get_referrer_for(\WP_Post $post) : ?object
76 {
77 $wc_orders_table = Query::get_table_name(Query::WC_ORDERS);
78 $views_table = Query::get_table_name(Query::VIEWS);
79 $sessions_table = Query::get_table_name(Query::SESSIONS);
80 $referrer_table = Query::get_table_name(Query::REFERRERS);
81 $referrer_query = Illuminate_Builder::get_builder();
82 $referrer_query->select('sessions.referrer_id', 'referrer', 'type AS referrer_type', 'domain')->from($wc_orders_table, 'orders')->leftJoin("{$views_table} AS views", function (JoinClause $join) {
83 $join->on('views.id', '=', 'orders.view_id');
84 })->leftJoin("{$sessions_table} AS sessions", function (JoinClause $join) {
85 $join->on('sessions.session_id', '=', 'views.session_id');
86 })->leftJoin("{$referrer_table} AS referrers", function (JoinClause $join) {
87 $join->on('referrers.id', '=', 'sessions.referrer_id');
88 })->where('orders.order_id', '=', $post->ID);
89 $record = $referrer_query->get()->first();
90 return $record;
91 }
92 }
93