Working with the Mixpanel API

We use Mixpanel at Cratejoy to track a lot of user interactions across the sites. However, there was a lot of profile data we were storing (and paying for) that we weren’t actually doing much with. So, I decided to see if it was possible to back up this data locally, create re-import files (in case we ever needed it again), and then delete in bulk.

Here’s some notes and tips about that process. Continue reading

How to Overwrite a Theme

If you’re trying to install a theme update manually, you might get this message:

Installing the themeā€¦
Destination folder already exists.
Theme install failed.

In order to update the theme, you’ll actually need delete the current version before you can upload the new one.

Here’s how to do that:

  • Go to “Appearance > Themes”
  • Temporarily switch to an alternate theme
  • Then, click “Theme Details” for the theme you are trying to replace
  • Click the “Delete” link in the bottom right
  • Now click the “Add New” button and upload the new theme version
  • Switch to the new version of the theme you uploaded

Limit Search Form to Specific Post Types

If you’d like to limit the search form on WordPress site to specific post types globally, there’s and easy way to do that:

[gist id=”ca2f2dff2d6fde3bfd1e” file=”limit-search-to-post-types.php” lines=”2-9″]

But let’s say you want to have a specific search form search limited to one post type, but allow other search forms to search all post types?

Most tutorials I’ve run across suggest that you re-create all the search form markup and then add a hidden input to the form like this:

[gist id=”ca2f2dff2d6fde3bfd1e” file=”limit-search-to-post-types.php” lines=”12-13″]

You can then conditionally load that hidden field on the specific templates where where it is needed.

However, if you’re using get_search_form() and don’t want to completely replace all the search form markup, an alternative would be to do a string replace before outputting the form:

[gist id=”ca2f2dff2d6fde3bfd1e” file=”limit-search-to-post-types.php” lines=”15-22″]

For more reading on how this filter works, you can read the great inline docs in the WordPress codebase itself.

Programmatically Update Settings in Staging

When developing WordPress sites I generally have three environments: live, staging, and local. Since I like my staging environment to be a very close replica of production, I frequently overwrite the database and files in staging. This is especially true when working with a host like WP Engine that has one-click staging environments.

However, when the database is overwritten in staging, there’s a generally a few settings that still need to be different from production. For instance, with WooCommerce sites, I may need to deactivate SSL and put Stripe into testing mode.

Occasionally I’ll also need to deactivate certain analytics plugins or third-party API integrations like MailChimp.

After making these updates manually for months, I finally moved to a programmatic update routine for many of my sites. The code basically just checks which environment we’re in. If it’s one of the staging environments and the update script hasn’t been run already, it runs it. Continue reading

Custom Conversion Tracking in WooCommerce

If you integrate any third-party services with your WooCommerce site (for ads, analytics, marketing, drop shipping, or A/B testing), it’s often helpful or necessary to provide conversion data through javascript.

A lot of the big services, like Google Analytics (tutorial) or Facebook ads, have off-the-shelf extensions you can use. But for smaller services, you often have to write some custom code to send them the conversion information.

Generally the easiest way to do this is by using the woocommerce_thankyou hook. This action is only fired on the order confirmation page and also provides the $order_id variable, which gives access to all the order details. Continue reading

Efficient Script Loading for oEmbeds

I’ve been using FitVids.js in a lot of recent themes to ensure video displays nicely in responsive layouts. I wrote about this in detail for a previous post.

The FitVids script is super tiny (1.7k), and I generally concat it will all my other scripts and then minify using Grunt. So, it’s really not a lot of additional page weight to include the script. However, I was just clued into an alternate method when doing a theme review for the Make theme on wordpress.org that could be slightly more efficient.

Generally FitVids will only be required if video is loaded via an oEmbed (YouTube, Vimeo). So, if we hook into the oEmbed and already have the FitVids registered to load in wp_footer, we can just enqueue the script when it is needed. Continue reading

Tracking eCommerce in WordPress

If you run any type of eCommerce site, it’s important to understand how visitors found your site and which specific entry pages led to a conversion. Tracking data can also let you know the type of content or marketing that is worth investing in.

Here’s a screenshot from a basic eCommerce dashboard I have set up in Google Analytics for a client with a WooCommerce shop (some data changed to make anonymous):

woocommerce-dashboard

Seeing the top referrers, landing pages, and revenue at a glance is great. But once the eCommerce data is in Google Analytics, you also drill down and answer very specific questions.

For instance, is an ad campaign on one site performing better than another? Should ad traffic be sent to the home page or the shop page? What is the conversion rate (or total revenue numbers) for visitors from Google who landed on an article page via an organic search? Continue reading