Using Logic Hop with Google Analytics

Note: Google Analytics functionality requires the Logic Hop Google Analytics Add-on.

Google Analytics & Logic Hop

The Google Analytics Add-on for Logic Hop allows you to easily track events using Logic Hop Goals.

Any Logic Hop Goal can send event data to Google Analytics when Logic Hop Conditions are met or when Goals are triggered with Javascript.

Use cases for Event Tracking with Logic Hop include tracking:

  • Outbound link clicks
  • Video playbacks
  • Lead scores
  • Complex, multi-step actions

Learn more about Logic Hop Goals.
Learn more about Event Tracking with Google Analytics.

Tutorial: Setting Goals & Tracking Events

View the code samples.

Configuring Google Analytics

Configuring Google Analytics

Download and install the Google Analytics Add-on. Click here for Add-on installation and update instructions.

On the Logic Hop Settings page, input your Google Analytics ID.

Check Enable Javascript Embed to automatically embed the Google Analytics website tracking code on every page of your website. Leave this box unchecked if you are already embedding Google Analytics using other means.

Click Save Changes.

Event Tracking

Google Event Tracking

To enable Event Tracking for a Logic Hop Goal, check the Send Event to Google Analytics on the Google Event Tracking palette and add specify your tracking data:

  • Category
    • Typically the object that was interacted with (e.g. ‘Video’)
  • Action
    • The type of interaction (e.g. ‘play’)
  • Label (Optional)
    • Useful for categorizing events (e.g. ‘Fall Campaign’)
  • Value (Optional)
    • A numeric value associated with the event (e.g. 42)

Logic Hop Variables

Logic Hop variables can also be used as data values using Liquid-style markup such as:

  • {{Source}}
  • {{LeadScore}}
  • {{QueryStore:#variable_name#}}

Logic Hop variables requires Google Analytics Add-on v1.0.1 or higher.

Note: Category and Action must be set for the event to be tracked. When using Logic Hop data variables for Category and Action, if the value is empty or null the event will not be tracked.

Event data is sent to Google using the Google Measurement Protocol.

Testing Event Tracking

Open an incognito window in your browser and open the Javascript Console.

Locate the Goal ID in the Goal editor. It can be found under the Javascript header.

Enter the logichop_goal() function in the Javascript Console with your Goal ID. If your Goal ID is 42, you would enter:

logichop_goal(42);

Check to see if the event data was received in Google Analytics under:

  • Reports > Real-Time > Events

More about Google Real-Time Events.

Code Samples

Copy and paste the code samples into you pages and posts. Make sure to update the Goal ID to match the Goal ID of your goal.

Javascript samples require jQuery and use the default WordPress jQuery prefix.

Set Goal When Link is Clicked

The following code triggers a Goal when any HTML element with the class “my-outbound-link” is clicked. This works with link or any other element. Replace ’42’ with your Goal ID.

<a href="https://logichop.com" class="my-outbound-link">Checkout Logic Hop!</a>

<script>
jQuery('.my-outbound-link').click(function () {
logichop_goal(42);
});
</script>

Set Goal When YouTube Video Playback Starts

The following code uses the YouTube Iframe API and triggers a Goal when the video is played. Replace ‘##YOUTUBE VIDEO ID##’ with your YouTube Video ID and ’42’ with your Goal ID.

<div id="player"></div>

<script>
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubeIframeAPIReady () {
new YT.Player('player', {
videoId: '##YOUTUBE VIDEO ID##',
events: {
'onStateChange': function (e) {
if (e.data == 1) {
logichop_goal(42);
}
}
}
});
}
</script>

Set Goal When Users Scrolls Within 100 Pixels of Page Bottom

The following code triggers a Goal when the user scrolls within 100 pixels of the bottom of the page. Replace ’42’ with your Goal ID.

<script>
jQuery(window).scroll(function() {
if (jQuery(window).scrollTop() + jQuery(window).height() > jQuery(document).height() - 100) {
logichop_goal(42);
}
});
</script>