Adding a tag on an action
One way to trigger custom events from other plugins in the funnel builder is to add a tag whenever an action is completed.
This acts as an alternative to creating a custom benchmark.
The Plugins API is what you hook into and doesn’t require a ton of custom development.
<?php add_action( 'purchased_a_product', 'add_a_tag_when_purchasing', 10, 2 ); /** * @param $customer Customer * @param $order Order */ function add_a_tag_when_purchasing( $customer, $order ) { $tags_to_add = [ 'Purchased Product', 1, 17, 'other-tag' ]; // You can use any combination of text or tag Ids // There are several ways to retrieve a contact record at this point, choose the most relevant one. // Option A: Use the tracking cookie. $contact = \Groundhogg\Plugin::$instance->tracking->get_current_contact(); if ( ! $contact ){ return; } $contact->apply_tag( $tags_to_add ); // Option B: Create a new contact record, or retrieve data from passed variables $email = $customer->email; $first_name = $customer->first_name; $contact = new \Groundhogg\Contact( [ // This will retrieve any existing contact with the given email, 'first_name' => $first_name, // If none exists a new record will be created. 'email' => $email ] ); $contact->apply_tag( $tags_to_add ); }