1

WordPress Plugin [Deprecated]

Official support from Segment for this plugin is deprecated. The current version of this plugin should be free of bugs but any existing and future development will be paused for the time being. We recommend exploring and using third-party alternatives.

We are currently looking for community maintainers!  If you’re interested in maintaining or contributing to our Wordpress plugin, we'll gladly send some Segment swag your way in return for any merged PRs. Don't forget to give us a heads up via our contact form when you submit a PR.  


Overview

Our WordPress plugin lets you record analytics from your WordPress site. It uses the client-side Analytics.js routing and takes only a minute to setup!

The plugin automatically collects page views and identifies users when they log in. You’ll have a basic analytics set up without a single line of code.

Our plugin even tracks WooCommerce and WP eCommerce events automatically following ourE-Commerce Tracking Guide.

Getting Started

Installing our WordPress plugin is really quick:

  1. Go to the Plugins > Add New page in your WordPress admin.
  2. Search for Segment and install Analytics for WordPress - by Segment.
  3. Click Activate Plugin.
  4. Click the plugin’s Settings button and enter your Segment source’s Write Key into the field and hit save.

That’s it, you’re done! You’ll automatically be identifying users and recording their actions as they move around your WordPress site.

Now just turn on any of our integrations on your integrations page and we’ll start sending your data to them for you!

Common Questions

What user information does it record automatically?

We automatically track a Logged In event, as well as identify users that are logged in to your WordPress site, and we record their nameemailusername, and website, so you don’t need to write any special code to handle that yourself. We also identify commenters if we can.

Which actions does it record automatically?

Just by installing the plugin, without touching any code, we’ll already be recording events based on the different types of pages the user visits:


Viewed Home Page

When the user views your home page, whether it’s a static page or a list of recent posts.

 

Viewed Post

When the user views a post. If they’re viewing a custom post type, we’ll use its name instead.

 

Viewed Author Page

 

When the user views an archive of posts by a specific author.

 

Viewed Category Page

 

When the user views an archive of posts in a specific category.

 

Viewed Tag Page

 

When the user views an archive of posts with a specific tag.

 

Viewed Search Page

When the user views the search results page.

We also automatically add useful properties to the events when applicable. For example, theViewed Search Page event includes a query property of what the user searched for.

Custom Events

For the most basic install, you’re already good to go. But if you want to add your own custom tracking to your WordPress code, there are two ways to do it. You can either add javascript directly, or you can use the global PHP Analytics object, which will just render the necessary javascript into your WordPress page.

Here’s the javascript you would add to track a custom event:

analytics.track('Song Played', {
  seconds: 268,
  artist: 'Kanye West'
});

If you prefer to write in PHP in WordPress template, here’s the PHP code to track the exact same custom event:

Analytics::track('Song Played', array(
  'seconds' => 268,
  'artist' => 'Kanye West'
));

event

String

 

 The name of the event you’re tracking. We recommend using human-  readable names like 'Song Played' or 'Status Updated'.

properties

Array, optional

 An array of properties for the event. If the event was 'Add Product',  it might have properties like 'price''product_type', etc.