DEV Community

David García
David García

Posted on

How I replaced 3 SaaS tools with a 50-line Python script

```html

Ever felt like you’re spending more time wrestling with SaaS tools than actually building your product? I get it. I’ve been there. Recently, I was drowning in a patchwork of tools – Buffer, Zapier, and Google Sheets – just to track basic website analytics and send out a simple daily report. It was a ridiculous amount of manual work and, frankly, a drain on my time. I decided to build a simple solution, and it saved me a ton of headaches.

The Problem: SaaS Overload

Let’s be honest, many SaaS tools are fantastic, but they’re often expensive and require a complex setup to truly get value. I was using Buffer to schedule social media posts, Zapier to connect Buffer to Google Sheets, and Google Sheets to actually see the data. Each tool had its own interface, its own quirks, and required constant monitoring to ensure everything was syncing correctly. The cost of Zapier alone was starting to feel excessive for what I was doing.

The Solution: A 50-Line Python Script

The answer wasn't another SaaS tool. It was a straightforward Python script to pull data from Google Analytics and send a daily email. It took me roughly 2 hours to build, and it completely eliminated the need for Zapier and Buffer for this specific task. Here’s a simplified example:

``` python

import google_analytics_v3

import smtplib

from email.mime.text import MIMEText

Replace with your GA credentials and email details

GA_CLIENT_ID = 'YOUR_GA_CLIENT_ID'

GA_USERNAME = 'YOUR_GA_USERNAME'

GA_PASSWORD = 'YOUR_GA_PASSWORD'

RECIPIENT_EMAIL = 'your_email@example.com'

SENDER_EMAIL = 'your_email@example.com'

Google Analytics Client Setup

ga = google_analytics_v3.AnalyticsClient(client_id=GA_CLIENT_ID, username=GA_USERNAME, password=GA_PASSWORD)

Sample Query (replace with your desired metrics)

query = {

"metrics": ["sessions", "pageviews"],

"dimensions": ["date"]

}

Fetch Data

data = ga.get_data(query)

Build Email

subject = "Daily Website Analytics Report"

body = f"Today's sessions: {data['rows'][0]['sessions']}\nToday's pageviews: {data['rows'][0]['pageviews']}"

msg = MIMEText(body)

msg['Subject'] = subject

msg['From'] = SENDER_EMAIL

msg['To'] = RECIPIENT_EMAIL

Send Email

with smtplib.SMTP('smtp.gmail.com', 587) as server:

server.starttls()

server.login(SENDER_EMAIL, GA_PASSWORD)

server.sendmail(SENDER_EMAIL, RECIPIENT_EMAIL, msg.as_string())

```

Let’s break down the key parts:

  • `google_analytics_v3`: A library to interact with the Google Analytics API.
  • The `query` dictionary defines what data we want to pull.
  • The `ga.get_data(query)` function fetches the data from Google Analytics.
  • The email sending section uses `smtplib` to send the report via email.

Practical Results

This script now automatically pulls daily website traffic data from Google Analytics and sends it to me via email. No more manual data collection, no more syncing issues, and no Zapier fees. The entire process is automated and incredibly reliable.

Conclusion & Next Steps

This example demonstrates how a simple Python script can significantly reduce your reliance on complex and often expensive SaaS tools. If you’re spending too much time managing integrations and syncing data, it’s time to consider automation. I've helped many businesses streamline their workflows and reduce operational costs.

Want to explore how automation can benefit your business? Schedule a free consultation today to discuss your specific needs and see how we can build a custom solution.

```


Itelnet Consulting

Top comments (0)