Extending Logic Hop

Quick Reference

Overview

Logic Hop offers a number of add-on integrations to connect third-party services such as Google Analytics, Drip and WooCommerce to provide personalization through conditions, goals and data display. We are constantly working to add new integrations so if there’s one you’d like to see, please contact us and let us know.

If you’re interested in building your own integration a great starting point is to download one of our existing add-ons and modify the code to work for your needs.

With Logic Hop 3.1.5 we’ve added functionality to make it easier to directly integrate data without an add-on integration through our Custom Object functionality.

Logic Hop Custom Object

The Logic Hop Custom Object is an empty container within the Logic Hop dataset to which you can read and write data. This data is available for individual users during their session on your website.

The Custom Object has no persistence beyond the current session, and if needed on repeat visits, you can associate specific users with their unique Logic Hop UID. User sessions end when the user quits their browser or after a period of inactivity – Typically twenty minutes.

Custom Object data is never sent to or stored in the Logic Hop database, so you can use it any way you see fit.

Note: Logic Hop stores temporary data in PHP sessions so it is important to take the amount of data into consideration. Smaller bits of data, such as numeric IDs, which can be looked up against other systems are typically ideal.

Store Custom Object Data with PHP

Storing data in the Custom Object with PHP is done using the logichop_update_data hook to pass your key and data into the $logichop->set_data( key, data ) method.

The following code adds an object to the key ‘my_key’:

function my_custom_stuff () {
    global $logichop;

    $my_data = new stdclass();
    $my_data->user_gender = 'female';
    $my_data->user_age = 42;

    $logichop->set_data( 'my_key', $my_data );
}
add_action( 'logichop_update_data', 'my_custom_stuff', 10, 2 );

Once your data has been stored in the Custom Object it is immediately accessible for use in conditions and display. The data can also be retrieved with Javascript or PHP.

Note: Custom Object keys must be a valid PHP variable name.

Learn how to viewed stored variables for testing.

Retrieve Custom Object Data with PHP

Custom Object data can be retrieved with PHP in the same manner as any Logic Hop data.

Echo Logic Hop data via PHP:

global $logichop;

$logichop->get_data('Custom.my_key');

Return Logic Hop data via PHP:

global $logichop;

$my_key = $logichop->get_data('Custom.my_key', false);

Learn more about Logic Hop data variables.

Retrieve Custom Object Data with Javascript

Custom Object data can be retrieved with Javascript in the same manner as any Logic Hop data.

Return Logic Hop data via Javascript:

var my_key = logichop_var('Custom.my_key');

Learn more about Javascript Variables

Display Custom Object Data with Logic Tags

Similar to standard Data Logic Tags, Custom Object Logic Tags can be used to display content within pages and posts.

The following will display the user’s age’:

{{ var: Custom.my_key.user_age }}

Learn more about Data Logic Tags.

Evaluate Custom Object Data with Conditions

Logic Hop provides Custom Object Condition Types within the Logic Hop Condition Builder. These can be used to evaluate Custom Object data and personalize content based on the results.

Custom Object Condition

Condition Types

  • Custom Data Object
    • Is the Custom Data Object variable set to a specific value.
  • Custom Data Object Contains
    • Does the Custom Data Object variable contain a specific value.

Learn more about conditions.