0

I'm setting up a new form tracking system for my website (the form framework is Gravity forms).

The codebase consists in a parent theme, plus 3 child theme (one for the main website, one for the shop, and another for another branch of the business).

I have a general class in the parent theme which sets up a basic tracking for every gravityforms form using the gform_after_submission filter.

class CustomGF {

 // ... some vars

  public function __construct() {
    // Events tracking
    add_filter( 'gform_after_submission', [$this, 'track_conversion'], 10, 2 );
   
    // ...other construct functions
   
   }
   
   public function track_conversion($entry, $form) {
     $trackingArgs = [
       // ... some arguments
     ];

    $trackingArgs = apply_filters('ll/tracking_args', $trackingArgs);
    // ... tracking code here
   }
}

After the basic setup, for some specific forms I want to alter the tracking arguments.

So in my child theme I have an additional class which uses the `gform_after_submission_{form_id}' filter to alter the behavior of the tracking for some forms:

class GFChild extends CustomGF {
  
  public function __construct() {
    add_action( 'gform_after_submission_9', [$this, 'submission_business_visit'], 10, 2);
  }

  public function submission_business_visit($entry, $form) {
    add_filter('ll/tracking_args', function() {
       $newArgs = [
         // ... new args here
       ];
       
       return $newArgs;
    }
  }
}

But apparently the add_filter('ll/tracking_args') call in the child theme is not working. Any advice on how to make it work?

Thanks!

1 Answer 1

1

The ll/tracking_args filter is called by the track_conversion() method, and this function is added to the execution in the constructor of the CustomGF class.

The GFChild class has its own constructor, so the constructor of the base class CustomGF is not executed. In the GFChild constructor also add track_conversion() function to ll/tracking_args filter or call parent constructor.

class GFChild extends CustomGF {

    public function __construct() {
        // Events tracking
        add_filter( 'gform_after_submission', [$this, 'track_conversion'], 10, 2 );

        add_action( 'gform_after_submission_9', [$this, 'submission_business_visit'], 10, 2);
    }
}

Or

class GFChild extends CustomGF {

    public function __construct() {
        //
        // call parent constructor at the beginning or end
        //
        parent::__construct();

        add_action( 'gform_after_submission_9', [$this, 'submission_business_visit'], 10, 2);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.