<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sasireka Balasubramaniyam</title>
    <description>The latest articles on DEV Community by Sasireka Balasubramaniyam (@sasireka_).</description>
    <link>https://dev.to/sasireka_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3917949%2F0d322124-a2a4-444d-943c-dd815a2cb8b8.jpg</url>
      <title>DEV Community: Sasireka Balasubramaniyam</title>
      <link>https://dev.to/sasireka_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sasireka_"/>
    <language>en</language>
    <item>
      <title>Website chatbots: What they are, why you need them, how to build them</title>
      <dc:creator>Sasireka Balasubramaniyam</dc:creator>
      <pubDate>Tue, 12 May 2026 08:54:04 +0000</pubDate>
      <link>https://dev.to/sasireka_/website-chatbots-what-they-are-why-you-need-them-how-to-build-them-4dn6</link>
      <guid>https://dev.to/sasireka_/website-chatbots-what-they-are-why-you-need-them-how-to-build-them-4dn6</guid>
      <description>&lt;p&gt;You have a good UX and landing page, even though your visitors are not converting to customers. Something is missing. If a visitor visits your site at 2 PM and searches for something but doesn’t get it. They can’t get what they search for. Because there is no assistant who explains your site, and we can’t hire someone for that.&lt;/p&gt;

&lt;p&gt;In this situation, a website chatbot helps to solve your problem. This post explains to you clearly what a website bot is, why it is needed, and how to build one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a website chatbot? 🤖
&lt;/h2&gt;

&lt;p&gt;A website chatbot is an AI automated tool that interacts with visitors in real time. This tool gives support, 24/7, and recommendations in real time. This chatbot is usually embedded in the website's corner. It should not be a generic one. We have to feed the specific knowledge into this. You have to feed the website information and additional knowledge base about your company.&lt;/p&gt;

&lt;p&gt;There are mainly two types of chatbots available.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Rule-based chatbots&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AI-powered chatbots&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Rule-based chatbots&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;AI-powered chatbots&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;It follows decision trees and keywords&lt;/td&gt;
&lt;td&gt;It uses NLP/LLMs to understand and generate real-time responses in natural language&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;It is best for FAQs, simple navigation, lead capture systems&lt;/td&gt;
&lt;td&gt;It is best for complex queries, customer support, and sites that have personalised help&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In recent days, modern chatbots can have both types. Rule-based structure and natural language processing to understand the conversation with humans.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a chatbot is needed for our website
&lt;/h2&gt;

&lt;p&gt;We developed a website, and it went live. Each visitor reaches our website for specific reasons. They search for their solution among multiple pages, and they may miss the content they actually want. This is the hard truth. Most website visitors leave without finding what they came for. There may be an answer, but they can’t find it fast enough. They don’t want to fill out the contact form, and they don’t want to wait for 24 hours reply from support.&lt;/p&gt;

&lt;p&gt;Here, a website chatbot helps you to solve those issues. It works 24/7, no breaks and no holidays. This will chat with the human in natural language.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Availability time - 24/7 ready to reply at any time&lt;/li&gt;
&lt;li&gt;Response - It responds immediately after the customer’s question&lt;/li&gt;
&lt;li&gt;Scalable - At the same time, it handles many customers' inquiries&lt;/li&gt;
&lt;li&gt;Accuracy - It gives accurate data that we provide to it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This automation need is universal. From e-commerce stores to healthcare, it is a need. Below is a sample website chatbot conversation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxgvkg205aq6awhu56mvr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxgvkg205aq6awhu56mvr.png" alt="chatbot sample image" width="405" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to build a website chatbot
&lt;/h2&gt;

&lt;p&gt;A few years ago, we needed to start building a chatbot from scratch. But now the situation has changed. There will be a lot of chatbot builder platforms. You don’t need to write any code. They handle all technical parts, and you just need to configure it with your website. Many providers are available, like Manychat, Agentzee, Live chat, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  How it actually works
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2cavjphl2wnqeik9g8q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2cavjphl2wnqeik9g8q.jpg" alt="a website chatbot response" width="800" height="1096"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how a website chatbot responds to the user's text message. It just responds according to the data we feed. If you want to know how to build using a third-party provider, just refer to the blog &lt;a href="https://agentzee.ai/blogs/more-traffic-less-retention-a-website-ai-chatbot-changes-that" rel="noopener noreferrer"&gt;More Traffic, Less Retention? A Website AI Chatbot Changes That&lt;/a&gt;. If you have any doubts regarding this, just comment.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>websitechatbot</category>
    </item>
    <item>
      <title>Google OAuth 2.0 vs Service account: Which one should you use?</title>
      <dc:creator>Sasireka Balasubramaniyam</dc:creator>
      <pubDate>Mon, 11 May 2026 12:24:23 +0000</pubDate>
      <link>https://dev.to/sasireka_/google-oauth-20-vs-service-account-which-one-should-you-use-5ed6</link>
      <guid>https://dev.to/sasireka_/google-oauth-20-vs-service-account-which-one-should-you-use-5ed6</guid>
      <description>&lt;p&gt;Authentication plays a crucial role in fetching real data from Google platforms like Gmail, Google Ads, Google Analytics, etc. When you try to authenticate your account to fetch data via API, you need to follow some steps. But there are two methods you can use. Both methods do the same job in authentication.&lt;/p&gt;

&lt;p&gt;In this guide, we’ll see about two methods and how to generate an access token using them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tow methods
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;OAuth client 2.0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Service account&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Feature&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Client 2.0&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Service Account&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Acts as&lt;/td&gt;
&lt;td&gt;Behalf of a user&lt;/td&gt;
&lt;td&gt;application itself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Requires user login?&lt;/td&gt;
&lt;td&gt;Yes ✔&lt;/td&gt;
&lt;td&gt;No ❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;User facing apps&lt;/td&gt;
&lt;td&gt;server to server or automation apps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Credentials&lt;/td&gt;
&lt;td&gt;Clinet ID and Client secret needed&lt;/td&gt;
&lt;td&gt;JSON key file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Token type&lt;/td&gt;
&lt;td&gt;Access token and refresh token&lt;/td&gt;
&lt;td&gt;Only access token&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Token expiry&lt;/td&gt;
&lt;td&gt;Expire after every hour&lt;/td&gt;
&lt;td&gt;Don’t expire untill revoke&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Prerequesites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Google Cloud console account with the email ID &lt;a href="https://cloud.google.com/" rel="noopener noreferrer"&gt;https://cloud.google.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Appropriate Google product login. For example, if you are going to access Google Analytics data, then you should properly connect your site with a GA4 account.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Method 1: generate client ID and secret using client OAuth 2.0
&lt;/h2&gt;

&lt;p&gt;You can use this method when your app &lt;strong&gt;acts on behalf of a user.&lt;/strong&gt; Imagine it works when a user clicks ‘Connect Gmail’ and your app gets permission to read and write. These permissions based on the scopes you used while authenticating.  &lt;/p&gt;

&lt;h3&gt;
  
  
  How it works
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;User clicks a button ‘Connect Google Analytics’&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google shows a consent screen page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User clicks ‘Continue’ to give permissions, and it gives an &lt;strong&gt;authorization code&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Exchange within a minute to generate an access token and a refresh token&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using the access token, the server calls the API to get data on behalf of the user.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How to generate client ID and secret
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the Google Cloud console project or create a new project. If you have a doubt just refer to this blog &lt;a href="https://agentzee.ai/blogs/how-to-access-google-analytics-dashboard-data-via-api-with-an-access-token" rel="noopener noreferrer"&gt;https://agentzee.ai/blogs/how-to-access-google-analytics-dashboard-data-via-api-with-an-access-token&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search for “Google OAuth Platform,” select it, and click “Clients.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you created a new project, then it goes to the project configuration page. Clearly fill in all the details. If you choose an existing project, then create a new client directly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After creating a client, it shows the JSON file to download. Download it and save it somewhere.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpbk7v2odm2ctk1nja20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpbk7v2odm2ctk1nja20.png" alt="Client ID and client secret JSON" width="516" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  generate an access token
&lt;/h3&gt;

&lt;p&gt;Let’s see it in Python code. This uses Google’s authentication. So, it shows a consent screen with an authorization code. Here, let's see how to generate an access token for Google Analytics.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Generate an authorization code
&lt;/h4&gt;

&lt;p&gt;For this, you need some Python libraries called google-auth, google-auth-oauthlib, and google-auth-httplib2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google_auth_oauthlib.flow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.auth.transport.requests&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.oauth2.credentials&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Credentials&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_auth_url&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;flow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Flow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_client_secrets_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Google_Analytics_Cred.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;scopes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://www.googleapis.com/auth/analytics.readonly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="n"&gt;redirect_uri&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_REDIRECT_URI&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;auth_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;flow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authorization_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;consent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;access_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;offline&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;auth_url&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, replace your redirect URI and place your downloaded JSON file path. If the JSON file is in another path, just mention the full file path. Then you will get a URL and open it in a browser. Select an account associated with Google Analytics. It will redirect to the URL you specify in the client, and you can find the code in the browser URL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotx3xywfug1ccdi5o2zi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotx3xywfug1ccdi5o2zi.png" alt="authorization code generation" width="800" height="97"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Exchange the authorization code for an access token
&lt;/h4&gt;

&lt;p&gt;Here, replace your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google_auth_oauthlib.flow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.auth.transport.requests&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.oauth2.credentials&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Credentials&lt;/span&gt;
&lt;span class="n"&gt;flow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Flow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_client_secrets_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Google_Analytics_Cred.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;scopes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://www.googleapis.com/auth/analytics.readonly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="n"&gt;redirect_uri&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_REDIRECT_URI&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;flow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch_token&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;auth_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;creds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;flow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;credentials&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;creds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;creds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;creds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;refresh_token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this, you can get your access token.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 2: Access token via Service account
&lt;/h2&gt;

&lt;p&gt;You can use a service account when your app doesn’t need user interaction. It is actually a server-to-server, with no user involvement. It represents an application, not a user.&lt;/p&gt;

&lt;h3&gt;
  
  
  How it works
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Google Cloud project (You can use the same project you created for OAuth 2.0)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a service account and download the JSON key file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google verifies the signature using your public key in the JSON file and returns an access token.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Call Google APIs directly&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Generate JSON key file
&lt;/h3&gt;

&lt;p&gt;Here, we use Python code to generate an access token with the JSON key file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Google Cloud Console. Open an existing project or create a new one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search for “I AM Admin” and select “Service Account” from the side menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the “Create new Service account” button&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Fill all the necessary fields. Your service account has been created. Then click the created account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ydxn7bxl7ellytr3yzl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ydxn7bxl7ellytr3yzl.png" alt="Service account created" width="799" height="305"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click keys → Add key → Create new key → Choose JSON type for ease access → Click create.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After this, your private key file will be directly downloaded to your system. This is never expiry until you manually delete it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkrxxg8jpbbtlccqc6hvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkrxxg8jpbbtlccqc6hvk.png" alt="Key file generation" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Generating an access token
&lt;/h3&gt;

&lt;p&gt;Store your downloaded private JSON key file in your code folder. Here’s the Python code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;google.auth&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;google.auth.transport.requests&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.oauth2&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;service_account&lt;/span&gt;

&lt;span class="c1"&gt;# Path to your service account JSON key file
&lt;/span&gt;&lt;span class="n"&gt;SERVICE_ACCOUNT_FILE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;service-account-key.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;# Define the scopes your app needs
&lt;/span&gt;&lt;span class="n"&gt;SCOPES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://www.googleapis.com/auth/analytics.readonly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# Load credentials from the key file
&lt;/span&gt;&lt;span class="n"&gt;credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;service_account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Credentials&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_service_account_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;SERVICE_ACCOUNT_FILE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;scopes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;SCOPES&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Request the access token
&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;transport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# ✅ Your access token
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Access Token:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Expires At:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expiry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace your credential file path. From this code, you can access an access token. Using that access token you can directly pull out the data from the Google Analytics dashboard, and it never expires.&lt;/p&gt;

&lt;p&gt;Both methods look similar, but you should understand where to use which method. It makes your way clear. Both access tokens work to fetch data. If you have any doubts or suggestions, post them in the comment section.&lt;/p&gt;

</description>
      <category>google</category>
      <category>oauth</category>
      <category>authentication</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Google Analytics 4: access data via Data API (Step-by-step)</title>
      <dc:creator>Sasireka Balasubramaniyam</dc:creator>
      <pubDate>Mon, 11 May 2026 09:04:52 +0000</pubDate>
      <link>https://dev.to/sasireka_/google-analytics-4-access-data-via-data-api-step-by-step-3ca</link>
      <guid>https://dev.to/sasireka_/google-analytics-4-access-data-via-data-api-step-by-step-3ca</guid>
      <description>&lt;p&gt;If you want to build a custom report or dashboard for your Google Analytics data in your app or website, you have to use the Google Analytics Data API v1. In this beginner tutorial, you’ll learn about the OAuth process and query the GA4 property data programmatically. &lt;/p&gt;

&lt;p&gt;Before beginning, make sure you have this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Google Analytics account with a property set up&lt;/li&gt;
&lt;li&gt;A basic knowledge of REST APIs in Python.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Accessing GA4 data using Google Analytics Data API v1
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Create a cloud project
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the Google Cloud Console using the link &lt;a href="https://cloud.google.com/" rel="noopener noreferrer"&gt;https://cloud.google.com/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Log in using your mail ID&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click console on the top right corner and click ‘My first Project’, and create a new project with all necessary data&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7r86lezo926xush36b7l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7r86lezo926xush36b7l.png" alt="Creating a new project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Create client OAuth 2.0
&lt;/h3&gt;

&lt;p&gt;In this, we'll get a client ID and secret. Both datasets will be used for later authentication purposes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Search for ‘ Google OAuth Platform’ and click&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click clients and click ‘Get Started’. If you are working on a new project, then it asks for project configuration and requires you to fill in all necessary data. If you are working on an old project, it’s already one. Copy the client ID and secret.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figvp0s1hzqtlm4iroke9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figvp0s1hzqtlm4iroke9.png" alt="Complete project configuration"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After this, go to ‘Clients’ on the same page and click ‘Create client.’ Fill in all the necessary data. Application type based on your need, name, and add a redirect URI. This link should be valid. Because your access token code will be redirected to this link only.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fawulwbets5gwdo16xwyq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fawulwbets5gwdo16xwyq.png" alt="Creating OAuth client 2.0"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finally, your OAuth 2.0 client is created and you can download the credential file in JSON format.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7lup1xl2hdc8703b31mm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7lup1xl2hdc8703b31mm.png" alt="OAuth 2.0 client credentials JSON"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you have any doubts about this, refer to the blog &lt;a href="https://agentzee.ai/blogs/how-to-access-google-analytics-dashboard-data-via-api-with-an-access-token" rel="noopener noreferrer"&gt;https://agentzee.ai/blogs/how-to-access-google-analytics-dashboard-data-via-api-with-an-access-token&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 3: Enable Google Analytics Data API v1
&lt;/h3&gt;

&lt;p&gt;To access the Google Analytics Data from its dashboard we need to enable the API we want to use. Here, we retrieve the data through the Google Analytics Data API v1.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Search for ‘APIs and Services’ and select it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the ‘Enable APIs and Services’ button to enable the Data API&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search for ‘Google Analytics Data API’ and select it. There will be a button named ‘Enable’, and click this. Now we have enabled the required Google Analytics Data API.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3t4snjsnjo8jcp4ck56h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3t4snjsnjo8jcp4ck56h.png" alt="Enable GA4 Data API"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Generate an access token
&lt;/h3&gt;

&lt;p&gt;We did all the necessary steps. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Firstly we need to generate a code to authorize the user. This code will be used later to generate a token. Its life span is so short. Replace your client Id and redirect URL from the downloaded JSON.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copy and paste the link below into your browser. It will redirect to the page, and you will get the ‘code’. Just copy and store it somewhere.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://accounts.google.com/o/oauth2/v2/auth?client_id=YOUR_CLIENT_ID&amp;amp;redirect_uri=YOUR_REDIRECT_URI&amp;amp;response_type=code&amp;amp;scope=https://www.googleapis.com/auth/analytics.readonly&amp;amp;access_type=offline&amp;amp;prompt=consent
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgxtvwgpkayjjsuoym7e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgxtvwgpkayjjsuoym7e.png" alt="generative authorize code"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open Postman and create a new HTTPS request. Just copy the below Curl command in that and replace all your details, such as code, client ID, client secret, and redirect URI.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST https://oauth2.googleapis.com/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "code=AUTHORIZATION_CODE" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "redirect_uri=YOUR_REDIRECT_URI" \
-d "grant_type=authorization_code"
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Then you will get a response like this&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"access_token": "ya29.a0AfH6SMA...",
"expires_in": 3599,
"refresh_token": "1//0gdfgsdfg...",
"scope": "https://www.googleapis.com/auth/analytics.readonly",
"token_type": "Bearer"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now we get an access token. Using this access token, we can fetch Google Analytics dashboard data through the GA4 Data API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Accessing data through the Data API
&lt;/h3&gt;

&lt;p&gt;Here we can see how to fetch the active users’ data from the Google Analytics dashboard. Replace your access token and property ID from the Google Analytics dashboard, GA4 → Admin → Property details → Copy your property ID there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;PROPERTY_ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_GA4_PROPERTY_ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;ACCESS_TOKEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_ACCESS_TOKEN&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://analyticsdata.googleapis.com/v1beta/properties/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;PROPERTY_ID&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:runReport&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ACCESS_TOKEN&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Content-Type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;metrics&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;activeUsers&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dimensions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;date&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dateRanges&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;startDate&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;7daysAgo&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;endDate&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;today&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Status Code:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, activeUsers is a valid metric to fetch active users’ data. The response will be like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"rows"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"metric_names"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"activeUsers"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dimension_names"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"date"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start_date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"7daysAgo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"end_date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"today"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"20260508"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"activeUsers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"35"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"20260504"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"activeUsers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"32"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"20260511"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"activeUsers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can refer to valid dimensions and metrics in Google’s official documentation using the link &lt;a href="https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema" rel="noopener noreferrer"&gt;API Dimensions &amp;amp; Metrics  |  Google Analytics  |  Google for Developers&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Re-generate access token
&lt;/h3&gt;

&lt;p&gt;Your access token will expire after one hour. You can’t fetch data again. It shows a client error. So after every hour, you have to regenerate an access token by using the refresh token. This refresh token logic will help to regain the new access token. But after some days, the refresh token also expires. But it has a longer life than an access token.&lt;/p&gt;

&lt;p&gt;If the refresh token expires, it shows ‘Refresh Error’. Don’t worry, just authenticcate ur account again. Follow step 4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST https://oauth2.googleapis.com/token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;client_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_CLIENT_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;client_secret&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_CLIENT_SECRET &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;refresh_token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_REFRESH_TOKEN &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;grant_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;refresh_token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, replace your client ID, client secret, and refresh token obtained before. You will get the same refresh token again and again until it expires. If you have any doubts, feel free to reach out to me in the comments 📌.&lt;/p&gt;

</description>
      <category>googleanalytics</category>
      <category>tutorial</category>
      <category>api</category>
      <category>python</category>
    </item>
    <item>
      <title>GA4 report snapshot templates: User behavior, Sales and marketing performance</title>
      <dc:creator>Sasireka Balasubramaniyam</dc:creator>
      <pubDate>Fri, 08 May 2026 12:22:22 +0000</pubDate>
      <link>https://dev.to/sasireka_/ga4-report-snapshot-templates-user-behavior-sales-and-marketing-performance-4f33</link>
      <guid>https://dev.to/sasireka_/ga4-report-snapshot-templates-user-behavior-sales-and-marketing-performance-4f33</guid>
      <description>&lt;p&gt;Acquiring users to our website is not easy, and bringing them back is more difficult. But if our content reaches people, it will increase the sales and revenue. Initially, we can’t manually collect visitors’ data from our website. By using Google Analytics, we can achieve it. It details your data in numbers and in a report format.&lt;/p&gt;



&lt;h2&gt;
  
  
  What is GA4 and why it is used?
&lt;/h2&gt;

&lt;p&gt;The Google Analytics dashboard is one of Google's products. This dashboard is a visual representation of metrics and key performance indicators (KPI). It is mainly used to track your website analysis. Google Analytics consists of some pre-built templates inside the report section to explore data visually. These pre-built templates help to save your time for building manual reports from scratch.&lt;/p&gt;



&lt;h2&gt;
  
  
  Let’s build a Google Analytics report snapshot
&lt;/h2&gt;

&lt;p&gt;If you’ve never used Google Analytics, then just open &lt;a href="https://developers.google.com/analytics" rel="noopener noreferrer"&gt;https://developers.google.com/analytics&lt;/a&gt; and log in with your email. Next, create an account for your website. It asks for your website URL and fill other details correctly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faw9jq9df2jsujs9xs09w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faw9jq9df2jsujs9xs09w.png" alt="Google Analytics account creation" width="799" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have an account just skip the above step. After creating the account, you have to add the script to all pages, and then it will track the events that happen on your website. You can find the tag in Admin → Data streams → Select the stream you provide → Scroll down and find ‘View tag instructions’ → Select ‘Install Manually’&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzl4wsiq2mfo6fihqvio.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzl4wsiq2mfo6fihqvio.png" alt="Instruction tag to add website pages" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose the report snapshot template based on your business needs. Specific and accurate data will enough for detail analysis. This GS4 snapshot customization allows you to setup the dashboard as your needs.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Template 1: User behavior
&lt;/h3&gt;

&lt;p&gt;If you just want to see your website overview, top pages and screens data, daily users count like active users, new users and how many returning users, engagement metrics like engagement sessions, average engagement time, scrolling and events. This template is enough to find those metrics in one dashboard.&lt;/p&gt;

&lt;p&gt;From this data you can optimise your website UI and content quality to bring more traffic. This template is more useful for content creators who can check which article page brings more attention, developers who can identify whether the new page or content reaches after deployment, and any site that focuses on engagement more than revenue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59bdh9avm4h8z93uje9n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59bdh9avm4h8z93uje9n.png" alt="User behavior template" width="800" height="427"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Template 2: Sales and Revenue 💰
&lt;/h3&gt;

&lt;p&gt;If you are running ecommerce business website or any other platform like Shopify, WooCommerce, or developers with in-app purchases and subscriptions on their website, or business owners who want to track their revenue-driving product for those, this template gives you the relevant metrics for your easy analysis. You can identify the top-performing product, which drives more revenue.&lt;/p&gt;

&lt;p&gt;This template directly connects the traffic sources with your revenue. So that you can identify the reason why revenue drops even though traffic is high and optimise the solution. It clearly describes which channels drive more traffic and purchases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2zxi7uk1873sd4qyqav9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2zxi7uk1873sd4qyqav9.png" alt="Sales and revenue template" width="799" height="422"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Template 3: Marketing performance
&lt;/h3&gt;

&lt;p&gt;This template measures marketing channel performance and attribute conversions. This template is best for digital marketers who run multiple-channel campaigns, SEO specialists to track their organic growth vs paid, and marketing teams who optimise and handle ad spend across all platforms like Google Ads, Meta and email.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This template covers some important things:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Channel groupings - organic, paid, social, referral searches side by side&lt;/li&gt;
&lt;li&gt;New users and returning users acquisition by their source or medium&lt;/li&gt;
&lt;li&gt;Conversion data - which channel gets more credits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxth8ec3mgo5ira9lcu2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxth8ec3mgo5ira9lcu2.png" alt="marketing performance template" width="799" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By knowing these template types, you can get the actual dashboard you want. You can avoid unwanted data. For example, if you are running a website for posting articles and there is no payment and subscription or purchase option, then there is no purchase data available in your Google Analytics report dashboard. So, you can clearly choose the ‘User behavior’ template.&lt;/p&gt;

&lt;p&gt;Initially, you can choose &lt;strong&gt;only one template for one account.&lt;/strong&gt; Later, you can customise this from Reports → library. I read about the important metrics in the blog &lt;a href="https://agentzee.ai/blogs/google-analytics-report-template-the-10-metrics-every-business-owner-should-track" rel="noopener noreferrer"&gt;https://agentzee.ai/blogs/google-analytics-report-template-the-10-metrics-every-business-owner-should-track&lt;/a&gt;. It makes you clearer. If you have any doubts or suggestions post them in the comments. Let's discuss.&lt;/p&gt;

</description>
      <category>googleanalytics</category>
      <category>webanalytics</category>
      <category>reportsnapshot</category>
      <category>dataanalytics</category>
    </item>
    <item>
      <title>Accessing Google Ads data via API is easy</title>
      <dc:creator>Sasireka Balasubramaniyam</dc:creator>
      <pubDate>Fri, 08 May 2026 06:21:25 +0000</pubDate>
      <link>https://dev.to/sasireka_/accessing-google-ads-data-via-api-is-easy-3ca5</link>
      <guid>https://dev.to/sasireka_/accessing-google-ads-data-via-api-is-easy-3ca5</guid>
      <description>&lt;p&gt;If you are going to build automation tools or marketing dashboards for Google Ads data, you need to pull it out through the API. It is easier than you think. This tutorial helps you access Google Ads data via API.&lt;/p&gt;

&lt;p&gt;Before this, you should have a Google Ads manager account and some campaign data. Next, we need to create a cloud project.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Google Cloud project? And why is it needed?
&lt;/h2&gt;

&lt;p&gt;Google Cloud project is act like an intermediator between the user and the user’s Google Ads account. You heard about authentication and authorisation. In technical we use OAuth. For this process we create a project with a secret ID and a key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Google Ads API integration
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Creating a cloud project
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open the Google Cloud console &lt;a href="https://console.cloud.google.com/" rel="noopener noreferrer"&gt;https://console.cloud.google.com/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;If you have an account and project, just use it. Otherwise create a new project.&lt;/li&gt;
&lt;li&gt;Click the console in the top right corner and then open ‘My First Project’. Create new project with all necessary data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagy5ozrp86ac8efu2zs4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagy5ozrp86ac8efu2zs4.png" alt="Google cloud project" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Creating client ID and secret
&lt;/h3&gt;

&lt;p&gt;This client ID and secret will be used for authentication purpose later.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search ‘Google OAuth Platform’ and click ‘Clients’&lt;/li&gt;
&lt;li&gt;If you created a new project, then it asks for the project configuration. Fill in all the necessary data. Otherwise create a client.&lt;/li&gt;
&lt;li&gt;Go to Clients → Create client. It asks for application type, based on your need choose one.&lt;/li&gt;
&lt;li&gt;Then fill in the application name and the redirect URI for callback.  The redirect URI will be valid.&lt;/li&gt;
&lt;li&gt;Download your credential file, and it disappears after closing the tab.&lt;/li&gt;
&lt;li&gt;This JSON consists of client ID and client secret, and other credentials.&lt;/li&gt;
&lt;li&gt;If you have any doubts about this step, just refer to the blog &lt;a href="https://agentzee.ai/blogs/how-to-access-google-ads-manager-data-via-api-with-an-access-token#steps-to-applying-for-a-developer-token" rel="noopener noreferrer"&gt;https://agentzee.ai/blogs/how-to-access-google-ads-manager-data-via-api-with-an-access-token#steps-to-applying-for-a-developer-token&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8tur5qzbwm3fqosrg399.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8tur5qzbwm3fqosrg399.png" alt="client creation" width="513" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Enable Google Ads API
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Search for ‘APIs and Services’&lt;/li&gt;
&lt;li&gt;Click ‘Enable APIs and services’&lt;/li&gt;
&lt;li&gt;Search for Google Ads API and click the ‘Enable’ button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxmp8g4o1ohzpbl8jw1zl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxmp8g4o1ohzpbl8jw1zl.png" alt="Enable google ads API" width="763" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Apply for a developer token
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open your Google Ads account dashboard &lt;a href="https://ads.google.com/" rel="noopener noreferrer"&gt;https://ads.google.com/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Go to Admin → API center. There, you can find the test developer token. For internal use, you can use this token.&lt;/li&gt;
&lt;li&gt;For production purposes, you should apply for the ‘Basic level’ or ‘Advanced level’ based on your needs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F97tddwtpffzco2ca63p9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F97tddwtpffzco2ca63p9.png" alt="Developer token in Google Ads account" width="474" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Generate an access token
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;After all these now we are going to generate an access token. By using the URL below in the browser we’ll get a ‘code’. We are going to fetch the data on behalf of the user. So we need to perform authentication. For that purpose we need to get the code and exchange it for generating the access token.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This ‘code’ lifetime is very short, so we need to use it immediately.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://accounts.google.com/o/oauth2/v2/auth?client_id=YOUR_CLIENT_
ID&amp;amp;redirect_uri=YOUR_REDIRECT_URI&amp;amp;response_type=code&amp;amp;
scope=https://www.googleapis.com/auth/adwords
&amp;amp;access_type=offline&amp;amp;prompt=consent
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Here, we need to replace the client ID and redirect URI from the JSON we downloaded before and hit the URL in the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It will redirect to the page we mentioned in the ‘redirect URI.’ Finally, just copy the code from the URL tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5n57skv1t1b6fxgz1kp5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5n57skv1t1b6fxgz1kp5.png" alt="Authentication code" width="800" height="97"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After copying the code, immediately paste it somewhere and hit the API to generate access token.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST https://oauth2.googleapis.com/token &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"code=AUTHORIZATION_CODE"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"client_id=YOUR_CLIENT_ID"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"client_secret=YOUR_CLIENT_SECRET"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"redirect_uri=YOUR_REDIRECT_URI"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"grant_type=authorization_code"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Here, replace your code, client ID, client secret, and redirect URI.&lt;br&gt;&lt;br&gt;
Hit the API in Postman or any platform you’ve regularly used.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You’ll see the output like this. Generally, this access token's life span is only one hour.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"access_token"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ya29.a0AfH6SMA..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"expires_in"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3599&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"refresh_token"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1//0gdfgsdfg..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"scope"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://www.googleapis.com/auth/adwords"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"token_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bearer"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Access Google Ads data via API
&lt;/h3&gt;

&lt;p&gt;Now you have an access token and a developer token. Follow the command below in Postman.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="s2"&gt;"https://googleads.googleapis.com/v16/customers/_CUSTOMER_ID_/googleAds:searc
h"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer ACCESS_TOKEN"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"developer-token: DEVELOPER_TOKEN"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"login-customer-id: MANAGER_ID"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
  "query": "
    SELECT
      campaign.id,
      campaign.name,
      metrics.impressions,
      metrics.clicks
    FROM ad_group
    WHERE segments.date DURING LAST_7_DAYS
  "
}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this, replace your generated access token, Developer token, and Manager ID from your Google Ads account and CUSTOMER_ID from your Google Ads account. Your response will be like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"results"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"campaign"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"123456789"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Search Campaign"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"metrics"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"impressions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"5400"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"clicks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"320"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more API references use this link &lt;a href="https://developers.google.com/google-ads/api/docs/client-libs" rel="noopener noreferrer"&gt;https://developers.google.com/google-ads/api/docs/client-libs&lt;/a&gt;. By using the APi you can fetch all data that is displayed on your Google Ads dashboard without opening it. It gives easy access to your data.&lt;/p&gt;

&lt;p&gt;To know more about this, kindly refer to the above blog. It clearly explains the steps and screenshots. If you have any doubts, refer to and clear. &lt;/p&gt;

&lt;p&gt;If you have any doubts or clarifications, don’t hesitate, just leave a comment. I hope this helps.&lt;/p&gt;

</description>
      <category>api</category>
      <category>apigateway</category>
      <category>automation</category>
      <category>agents</category>
    </item>
  </channel>
</rss>
