Skip to content

Commit

Permalink
Merge pull request #787 from woocommerce/add/pinterest-conversions
Browse files Browse the repository at this point in the history
Pinterest Conversions API
  • Loading branch information
message-dimke authored Aug 30, 2023
2 parents 591ce98 + 12d20e4 commit ff326f6
Show file tree
Hide file tree
Showing 19 changed files with 1,886 additions and 702 deletions.
26 changes: 0 additions & 26 deletions assets/source/js/pinterest-for-woocommerce-tracking.js

This file was deleted.

41 changes: 33 additions & 8 deletions class-pinterest-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
* @version 1.0.0
*/

use Automattic\WooCommerce\Pinterest as Pinterest;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
use Automattic\WooCommerce\Pinterest;
use Automattic\WooCommerce\Pinterest\AdCredits;
use Automattic\WooCommerce\Pinterest\AdCreditsCoupons;
use Automattic\WooCommerce\Pinterest\Admin\Tasks\Onboarding;
use Automattic\WooCommerce\Pinterest\API\UserInteraction;
use Automattic\WooCommerce\Pinterest\Billing;
use Automattic\WooCommerce\Pinterest\Heartbeat;
use Automattic\WooCommerce\Pinterest\Notes\MarketingNotifications;
use Automattic\WooCommerce\Pinterest\PinterestApiException;
use Automattic\WooCommerce\Pinterest\Tracking;
use Automattic\WooCommerce\Pinterest\Tracking\Conversions;
use Automattic\WooCommerce\Pinterest\Tracking\Data\User;
use Automattic\WooCommerce\Pinterest\Tracking\Tag;
use Automattic\WooCommerce\Pinterest\Utilities\Tracks;
use Automattic\WooCommerce\Pinterest\API\UserInteraction;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
use Automattic\WooCommerce\Pinterest\Admin\Tasks\Onboarding;

if ( ! class_exists( 'Pinterest_For_Woocommerce' ) ) :

Expand Down Expand Up @@ -263,7 +267,7 @@ public function init_plugin() {

// ActionScheduler is activated on init 1 so lets make sure we are updating after that.
add_action( 'init', array( $this, 'maybe_update_plugin' ), 5 );
add_action( 'init', array( Pinterest\Tracking::class, 'maybe_init' ) );
add_action( 'init', array( self::class, 'init_tracking' ) );
add_action( 'init', array( Pinterest\ProductSync::class, 'maybe_init' ) );
add_action( 'init', array( Pinterest\TrackerSnapshot::class, 'maybe_init' ) );
add_action( 'init', array( Pinterest\Billing::class, 'schedule_event' ) );
Expand Down Expand Up @@ -303,6 +307,28 @@ public function init_plugin() {

}

/**
* Initialise Tracker and add trackers to it.
*
* @since x.x.x
*
* @return Pinterest\Tracking|false
*/
public static function init_tracking() {
$is_tracking_disabled = apply_filters( 'woocommerce_pinterest_disable_tracking', false );
$is_tracking_conversions_disabled = ! Pinterest_For_Woocommerce()::get_setting( 'track_conversions' );
$is_not_a_site = wp_doing_cron() || is_admin();

if ( $is_tracking_disabled || $is_tracking_conversions_disabled || $is_not_a_site ) {
return false;
}

$tag_tracker = new Tag();
$user = new User( WC_Geolocation::get_ip_address(), wc_get_user_agent() );
$conversions_tracker = new Conversions( $user );

return new Tracking( array( $tag_tracker, $conversions_tracker ) );
}

/**
* Init Pinterest_For_Woocommerce when WordPress Initialises.
Expand Down Expand Up @@ -834,7 +860,7 @@ public static function get_middleware_url( $context = 'login', $args = array() )

// phpcs:ignore Squiz.Commenting.InlineComment.InvalidEndChar
// nosemgrep: audit.php.wp.security.xss.query-arg
return self::get_connection_proxy_url() . 'login/' . PINTEREST_FOR_WOOCOMMERCE_WOO_CONNECT_SERVICE . '?' . $state;
return self::get_connection_proxy_url() . 'connect/' . PINTEREST_FOR_WOOCOMMERCE_WOO_CONNECT_SERVICE . '?' . $state;
}


Expand Down Expand Up @@ -1375,10 +1401,9 @@ public static function is_domain_verified(): bool {
* @return boolean
*/
public static function is_tracking_configured() {
return false !== Pinterest\Tracking::get_active_tag();
return false !== Pinterest\Tracking\Tag::get_active_tag();
}


/**
* Returns the Terms object for the currently configured base country.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-pinterest-for-woocommerce-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private function get_component_settings() {
406 => 'domain verification',
409 => 'meta-tag',
),
'conflictingTagsWarning' => Tracking::get_third_party_tags_warning_message(),
'conflictingTagsWarning' => Tracking\Tag::get_third_party_tags_warning_message(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/API/FeedState.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function add_feed_registration_state( $result ) {
*/
public function add_third_party_tags_warning( $result ) {

$warning_message = Tracking::get_third_party_tags_warning_message();
$warning_message = Tracking\Tag::get_third_party_tags_warning_message();

if ( empty( $warning_message ) ) {
return $result;
Expand Down
Loading

0 comments on commit ff326f6

Please sign in to comment.