LLMS_Events::should_track_client_events()

Determine if client side events from the current page should be tracked.


Description Description


Return Return

(boolean)


Top ↑

Source Source

File: includes/class-llms-events.php

	protected function should_track_client_events() {

		$ret = false;

		/**
		 * Filter the post types that should be tracked
		 *
		 * @since 3.36.0
		 * @since 3.36.1 Remove redundant check on `is_singular()` and `is_post_type_archive()`.
		 *
		 * @param string[]|string $post_types An array of post type names or a pre-defined setting as a string.
		 *                                    "llms" uses all public LifterLMS and LifterLMS Add-on post types.
		 *                                    "all" tracks everything.
		 */
		$post_types = apply_filters( 'llms_tracking_post_types', 'llms' );

		if ( 'all' === $post_types ) {
			$ret = true;
		} elseif ( 'llms' === $post_types ) {

			// Filter public post types to include LifterLMS public post types.
			$post_types = array_keys( get_post_types( array( 'public' => true ) ) );
			foreach ( $post_types as $key => $type ) {
				if ( ! in_array( $type, array( 'course', 'lesson' ), true ) && 0 !== strpos( $type, 'llms_' ) ) {
					unset( $post_types[ $key ] );
				}
			}
		}

		if ( ! is_array( $post_types ) ) {
			$ret = false;
		} elseif ( is_singular( $post_types ) ) {
			$ret = true;
		} elseif ( is_post_type_archive( $post_types ) ) {
			$ret = true;
		} elseif ( is_llms_account_page() || is_llms_checkout() ) {
			$ret = true;
		}

		/**
		 * Filters whether or not the current page should track client-side events
		 *
		 * @since 3.36.0
		 *
		 * @param bool $ret Whether or not to track the current page.
		 * @param string[] $post_types Array of post types that should be tracked.
		 */
		return apply_filters( 'llms_tracking_should_track_client_events', $ret, $post_types );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.36.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.