How to add Google Analytics and Facebook Pixel to WordPress
If you run a WordPress website, you probably want to know where your visitors come from and what they do after they arrive.
Google Analytics tracks website traffic, pages, events, and user behavior. Facebook Pixel, now part of Meta’s tracking setup, helps you measure visitors and actions that come from Facebook and Instagram.
You can add both to WordPress without editing your theme files.
What you need
Before you start, create these 2 accounts:
- A Google Analytics account
- A Meta Business account
You’ll also need access to your WordPress admin dashboard.
For Google Analytics, you’ll create a GA4 property and get your measurement ID. It looks like this:
G-XXXXXXXXXX
For Meta, you’ll create a Pixel in Meta Events Manager and get a Pixel ID made up of numbers.
How to install Google Analytics on WordPress
Go to Google Analytics and sign in with your Google account.
Create a new property for your website. Enter your website name, choose your reporting time zone, and select the currency you use.
When Google asks for the platform, choose Web.
Enter your website address, then create the data stream.
After that, Google will give you a measurement ID such as:
G-1234567890
Copy it. You’ll need it in WordPress.
Add Google Analytics with a WordPress plugin
Using a plugin is the easiest option for most WordPress sites.
Install a plugin that supports Google Analytics and GA4. For example, you can use Site Kit by Google.
In WordPress, go to:
Plugins → Add New Plugin
Search for:
Site Kit by Google
Install and activate it.
Site Kit will ask you to connect your Google account. Follow the setup steps and connect your website to Google Analytics.
Once connected, Google Analytics can start collecting data from your WordPress website.
Give it some time before checking reports. A brand-new Analytics property won’t magically produce years of traffic data in 30 seconds.
Check whether Google Analytics is working
Open your website in a new browser tab.
Then open Google Analytics and go to the Realtime report.
Visit a few pages on your website yourself.
If your visit appears in the realtime report, Analytics is receiving data.
You can then use reports to see things such as:
- Visitors
- Traffic sources
- Popular pages
- Events
- User engagement
- Traffic from Google search
- Traffic from social media
How to add Facebook Pixel to WordPress
Meta calls this tool the Meta Pixel now, although you’ll still see many tutorials calling it Facebook Pixel.
Go to Meta Events Manager and create a Pixel for your website.
Choose the option to connect a new data source and select Web.
Enter a name for your Pixel and follow the setup steps.
Meta will give you a Pixel ID. Keep it somewhere safe.
It will look something like:
123456789012345
Add Meta Pixel with a WordPress plugin
You can add the Pixel through a WordPress plugin instead of manually placing code in your theme.
Go to:
Plugins → Add New Plugin
Search for a plugin that supports Meta Pixel or Meta for WordPress.
Install and activate it.
Connect your Meta account when the plugin asks for access. Select the Pixel you created in Events Manager and complete the setup.
The plugin will then place the required tracking code on your website.
Add Meta Pixel manually
You can also install the Pixel manually.
In Meta Events Manager, choose your Pixel and select the option to install the code yourself.
Meta will provide a JavaScript snippet.
Copy that code and add it to the <head> section of your WordPress website.
You can use a header/footer code plugin to do this without editing theme files.
For example:
Plugins → Add New Plugin
Install a trusted header and footer code plugin, activate it, and paste the Meta Pixel code into the header section.
Save your changes.
Be careful when pasting tracking code. One missing character can break the script.
Check whether Meta Pixel is working
Open Meta Events Manager and select your Pixel.
Look for incoming activity or events.
Then visit your WordPress website in another browser tab.
Meta should start receiving activity from your visit.
You can also use Meta’s testing tools to check whether events are being received correctly.
Google Analytics vs Meta Pixel
The 2 tools answer different questions.
Google Analytics helps you understand your website traffic and what visitors do on your site.
Meta Pixel connects website activity with your Meta advertising campaigns.
For example, suppose you spend ₹1,000 on Facebook Ads.
Someone clicks your ad, visits your WordPress website, views a product, and buys it.
Meta Pixel can send those website events back to Meta, helping you measure the result of that ad campaign.
Google Analytics can show you that the visitor came from a Meta-related traffic source and what happened during the website session.
Using both gives you 2 different views of the same visitor journey.
Track conversions on WordPress
Traffic numbers are useful, but conversions tell you whether the traffic is doing anything.
For a business website, you might track:
- Contact form submissions
- Product purchases
- Newsletter signups
- Button clicks
- Phone number clicks
- Appointment bookings
For a WooCommerce store, you can track events such as product views, add-to-cart actions and purchases.
Your exact setup depends on the plugins and tools running on your WordPress site.
Test everything before running ads
Do a test before spending money on advertising.
Open your website and perform the action you want to track.
For example, submit your contact form.
Then check Google Analytics for the event and Meta Events Manager for the corresponding activity.
If the event doesn’t appear, check your plugin settings and tracking code before launching your campaign.
A 10-minute test can save you from spending ₹5,000 and discovering later that your conversions weren’t being recorded.
Keep your tracking setup clean
Don’t install 4 different plugins that all add Google Analytics or Meta Pixel.
That can send duplicate events and make your reports messy.
Pick one method for Google Analytics and one method for Meta Pixel.
Also check your website’s privacy and cookie requirements based on where your visitors live. Tracking rules differ by country, so your consent setup should match your audience and business.