How to integrate segment data analytics into WordPress

May 14, 2019·4 min read
How to integrate segment data analytics into WordPress -


  • A segment is a single platform that collects, stores, and routes your user data to hundreds of tools with the flick of a switch.
  • So basically you can spend more time using your data and less time to track it down through a segment.
  • For more information about a segment, you can go through THIS link.

Analytics, marketing automation, email, user testing, error reporting, and support tools all require the same data: who are your users and what are they doing.

Without Segment, you have to instrument each tool separately, even though you send them all the same data. Segment eliminates this extra code and replaces the tool installation process.

You just send your data to us, then we translate and route it to all of your tools.

Use the Segment API to track user events like page views, clicks, and sign-ups on your mobile app and website. Next switch on marketing, product, and analytics tools you want to use in Segment’s control panel. Then Segment:

  • Collects and stores your data in one place
  • Prepares and translates the data into a format each tool understands
  • Sends the data to your designated tools, so you never have to install tracking again.


The first thing you need to make an account on segment website.

Then you can simply follow the instruction as given and after that, you just need to login into it.

After successful login, you need to create a workspace where you can simply add source.

In my case, I have already added one source but in your case, you need to add a source.

Simply clicks on “Add Source”. Then you will see the next screen..

You can select any sources for example “JavaScript”, “IOS”… But in my case, I have so many complexities and some custom functionalities as well so i have chosen “PHP” as a source.

If you can’t find “PHP” in a source list. Then just simply You can see a filter source section to the left top side. Just type “PHP”.

After selecting PHP, Just need to click on connect.

After, Simply clicks on “Add Source”.

Now, You need to download the library, clone the repository from GitHub into your desired application directory. or You can simply download the zip file and extract it to your application directory.

Here is the link where you can download the library or clone the repo.

After, You need to require the Segment.php file into your functions.php file.


Now, you’re ready to actually initialize the module.

class_alias('Segment', 'Analytics');

How you can find your source write key? let me show you how ?.

Click on Source -> Settings -> API’s ->WRITE KEY.

Now, the key point “Identify”.

The Method identify is how you tell Segment who the current user is. It includes a unique User ID and any optional traits that you might know about them.

Here’s what a basic call to identify might look like:

  "userId" => "17",
  "traits" => array(
    "name" => "Chirag Patel",
    "email" => ""


Track Action.

The track method is how you tell Segment about which actions your users are performing on your site. Every action triggers what we call an “event”, which can also have associated “properties”.

Here’s what a call to track might look like when a user signs up:

  "userId" => "17",
  "event" => "Logged in",
  "properties" => array(
    "Name" => "chirag",
    "Surname" => "Patel",
    "Email" => ""

So, As shown above, is the small overview of the segment and how you can integrate it into your WordPress website or any CRM.

you can check live events in “debugger” section.

Happy Coding!

Go back Home.