<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aayush Maggo on Medium]]></title>
        <description><![CDATA[Stories by Aayush Maggo on Medium]]></description>
        <link>https://medium.com/@aayushmaggo?source=rss-a3e1c4e68398------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hkA0SrBZm5ihjq5a.</url>
            <title>Stories by Aayush Maggo on Medium</title>
            <link>https://medium.com/@aayushmaggo?source=rss-a3e1c4e68398------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 03:25:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aayushmaggo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to reverse eCommerce transactions in Google Analytics using the Measurement Protocol]]></title>
            <link>https://medium.com/@aayushmaggo/how-to-reverse-ecommerce-transactions-in-google-analytics-using-the-measurement-protocol-c742968b2b1b?source=rss-a3e1c4e68398------2</link>
            <guid isPermaLink="false">https://medium.com/p/c742968b2b1b</guid>
            <dc:creator><![CDATA[Aayush Maggo]]></dc:creator>
            <pubDate>Mon, 28 Feb 2022 23:22:53 GMT</pubDate>
            <atom:updated>2022-02-28T23:22:53.362Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Quality is essential for Google Analytics, especially when analysing the Transactions and Sales Reports. In this article, I am sharing what to do when unwanted transactions enter into your Google Analytics account view and inflate your transactions, and outlines how you can remove these instances.</h4><h3>The scenario</h3><p>Let’s say a test order is placed by your development team on the site, and these test transactions are now visible in your main GA analysis view. You don’t want them there as these test transactions end up skewing your eCommerce reports. This affects the overall Data Quality of your account and makes your GA data inaccurate and unreliable.</p><p>This is a scenario that the HammaJack team came across recently for one of our clients, where a series of test conversions end up inflating the eCommerce stats.</p><p>The test conversions are a problem not just for your standard GA reports but will cause headaches when reporting from other tools such as <a href="https://datastudio.google.com/">Google Data Studio</a> which use GA as a source for reporting.</p><p>In addition to any test conversions, you could also find yourself wanting to remove any of the following transactions from Google Analytics:</p><ul><li>Fraudulent conversions</li><li>Cancelled orders</li><li>Refunded orders</li><li>Unfulfilled or declined transactions</li></ul><p>For simplicity’s sake I have grouped all of the above as ‘unwanted transactions’ as these will all end up causing discrepancies between your GA transaction data and the actual sales data.</p><p>In this article, I’ll be outlining all the steps required to remove unwanted transactions to make your reports accurate and trustworthy. But before we dive into the steps, let’s first understand what Google Measurement Protocol is.</p><h3>What is Google Measurement Protocol?</h3><p>Google Measurement Protocol is a set of rules that allows developers to send data to Google Analytics Servers from any device, so long as the device is connected to the Internet. While the GA tracking code placed on your website does this on its own, developers use the measurement protocol to send data in a format that the analytics server understands.</p><p>Every hit sent via the measurement protocol consists of two parts:</p><p><strong>Transport:</strong> This determines how the hit is sent. For Google Analytics server, this is always the HTTPs request made to the endpoint: <a href="https://www.google-analytics.com/collect">https://www.google-analytics.com/collect</a></p><p><strong>Payload:</strong> The content of the hit that looks like a URL query parameter string. Here’s an example of what a payload looks like — v=1&amp;t=transaction&amp;tid=UA-XXXXXXXX-X&amp;cid=b15d9d29–4387–4d24-b56c-9027fdf95e84</p><p>If you need a guide to learn more about the Google Measurement Protocol you can read about it <a href="https://developers.google.com/analytics/devguides/collection/protocol/v1">here</a>.</p><p>Utilising the measurement protocol allows us to reverse the unwanted transactions in Google Analytics.Whilst the tool is built for developers, you do not need any technical know-how to reverse transactions as long as you are following each step. With that said, let’s dive into the steps.</p><h3>Steps to reverse the unwanted transactions</h3><p><strong>Step 1</strong>: Make sure that you have the ‘Edit’ permissions to your analytics account. Go to Admin &lt; User Management to confirm.</p><p><strong>Step 2</strong>: Navigate to your Ecommerce reports and make a note of all the transaction ID’s you want to reverse. Go to Conversions &lt; Ecommerce &lt; Sales Performance.</p><p><strong>Step 3</strong>: Once the transaction ID’s are listed, go to the <a href="https://ga-dev-tools.appspot.com/hit-builder/">measurement protocol builder site</a>.</p><p>You will find a bunch of parameters here that will build the payload for our hit. There are hit types represented by ‘t’, version (v), tracking id (tid) and client id (cid)</p><p>Stick with the default version (v) set as 1, and change the hit type (t) to a transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p><strong>Step 4: </strong>Add your tracking id/web property id (tid) and generate a random client id.</p><p>Here’s what your basic set of parameters should look like;</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p><strong>Step 5</strong>: With the basic parameters covered, we’ll add a bunch more to include information for the transactions we want to remove.</p><p>Use the ‘Add Parameter’ button to add the following parameters and populate these with the transaction values;</p><ul><li><strong>Transaction ID (ti) — Required</strong></li><li>Transaction Revenue (tr)</li><li>Transaction Shipping (ts)</li><li>Transaction Tax (tt)</li><li>Item Quantity (iq)</li><li>Currency (cu)</li><li>Campaign Source (cs)</li><li>Campaign Medium (cm).</li></ul><p>Here’s what the parameter fields should look like:</p><p><strong>Few things to note here</strong>:</p><ol><li>Of the added parameters, only the transaction id is required to successfully send over the hit. However, as the goal is to reverse/remove the unwanted transactions, adding all the possible transaction details here including the transaction revenue, tax and shipping details will ensure that you successfully remove not only the transaction hit, but also update other reports that rely on eCommerce reporting.</li><li>Add the revenue, tax and shipping value with a negative sign as displayed in the screenshot above.</li><li>The above parameters should suffice for successful removal. If any of these values are not set, feel free to omit from the list.</li><li>Feel free to also add more information about the transaction. You can find the complete list of transaction parameters <a href="https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ecomm">here</a>.</li></ol><p><strong>Step 6: </strong>Validate and send the hit</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>On successful validation, click on ‘Send hit to Google Analytics’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p><strong>Step 7: </strong>Wait 15–20 minutes (it can take up to an hour) for the hit to be populated onto your Google Analytics view. Confirm the successful hit by navigating back to Sales Performance Report (Conversions &lt; Ecommerce &lt; Sale Performance).</p><p>Those are the complete list of steps required to successfully reverse the unwanted transactions. Please note that it is important to make the reverse transaction as soon as you are aware of it. You won’t see the test transaction if the reverse transaction is sent on the same day. However, if there is a delay of a day or more between the test and reverse transaction, Google Analytics will have two transactions (the original transaction and the reverse transaction).</p><p>Choose a duration of analysis to include the test and reverse transaction to stop the transaction from appearing.</p><h3>Bonus free template</h3><p>You can follow the above steps or simply grab our free hit builder Google Sheet and just follow the easy instructions. The hit builder sheet lists all the parameters you need to successfully reverse the transaction. Simply add the transaction values and copy your transaction hit.</p><p><a href="https://hammajack.com.au/transaction-reversal-hit-builder-for-google-analytics">Get the free hit builder template</a></p><h3>Most Important Point</h3><p>The last thing you want when analyzing your eCommerce data in Google Analytics is to have unwanted transactions enter into your Google Analytics account view, as this can skew your data and even make your account unreliable and untrustworthy. Thankfully you <em>can</em> remove these unwanted conversions (such as test or cancelled transactions), and if you use these steps as soon as you spot an unwanted transaction you can remove it with ease and continue to keep your data and reporting as clean and reliable as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c742968b2b1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Extract Multiple User Journey Paths in BigQuery]]></title>
            <link>https://medium.com/@aayushmaggo/how-to-extract-multiple-user-journey-paths-in-bigquery-6c5d76f5aeeb?source=rss-a3e1c4e68398------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c5d76f5aeeb</guid>
            <dc:creator><![CDATA[Aayush Maggo]]></dc:creator>
            <pubDate>Mon, 28 Feb 2022 23:19:11 GMT</pubDate>
            <atom:updated>2022-02-28T23:19:11.874Z</atom:updated>
            <content:encoded><![CDATA[<p>One important part of designing a great user experience is understanding the entire journey a user takes. Knowing how they move through your website/app is a major step to unlock users behaviour patterns and identify areas to optimise.</p><p>In this post, I’ve outlined steps to extract all the journey paths in GA via BigQuery, and then added a running percentage to find the most popular ones.</p><p>Note than you can view the same flows within the GA interface (Audience &lt; User Flow), however this report is sampled for large datasets, and will result in fewer sessions returned for your analysis.</p><p>Also, the navigation summary reports within the Behaviour Section is largely limited.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a-BNjABW74s2VYVt" /></figure><p>The other drawback is the inability to analyse the page and event flows together, an option that BigQuery allows you over and above what is possible in Google Analytics.</p><p>To demonstrate the steps, I have used the publicly available Google Analytics data set in Big query — bigquery-public-data:google_analytics_sample</p><h3>Step 1:</h3><pre>WITH<br>  <br>first_five_pages AS ( --- CTE<br>  <br>SELECT<br>    <br>CONCAT(fullVisitorId,&quot;-&quot;,CAST(visitstarttime AS string)) AS sessionId,<br>    <br>h.hitNumber,<br>    <br>h.page.pagePath AS landing_page,<br>    <br>LEAD(h.page.pagePath) OVER (PARTITION BY fullVisitorId, visitstarttime ORDER BY h.hitNumber) AS second_page,</pre><pre>LEAD(h.page.pagePath,2) OVER (PARTITION BY fullVisitorId, visitstarttime ORDER BY h.hitNumber) AS third_page,</pre><pre>LEAD(h.page.pagePath,3) OVER (PARTITION BY fullVisitorId, visitstarttime ORDER BY h.hitNumber) AS fourth_page,</pre><pre>LEAD(h.page.pagePath,4) OVER (PARTITION BY fullVisitorId, visitstarttime ORDER BY h.hitNumber) AS fifth_page,</pre><pre>CONCAT(trafficsource.source,&quot; / &quot;,trafficsource.medium) AS source_medium,</pre><pre>FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`,</pre><pre>UNNEST(hits) AS h</pre><pre>WHERE</pre><pre>_table_suffix BETWEEN &#39;20170101&#39;</pre><pre>AND &#39;20170631&#39;</pre><pre>AND totals.visits = 1</pre><pre>AND h.type=&quot;PAGE&quot; )</pre><p>The first section of the code creates a Common Table Expression, and uses the concatenate function to create unique session ids, and then extract the first five pages visited by users in the same session using a window function.</p><p>To query data from multiple tables, I have used the _table_suffix wildcard. The date range is from the start of the year 2017 to June 2017.</p><p>And to finish Step 1, I have added two conditions to the WHERE clause to only include the pageview interactions — ‘where totals.visits = 1 and hit type is page’.</p><h3>Step 2:</h3><pre>FILTER AS (</pre><pre>SELECT *</pre><pre>FROM first_five_pages</pre><pre>WHERE hitNumber = 1</pre><pre>AND REGEXP_CONTAINS(source_medium, &#39;google / organic&#39;)<br></pre><pre>)</pre><p>Next, we are going to add another Table that filters the GA traffic to conditions we want to set. I have filtered my query to show Users who landed organically via Google. You can add more to this by including more conditions, including filtering on transactions, subscriptions or any other events. The possibilities are endless here</p><p>The hitNumber = 1 in the where clause will filter to include only the first session hit only.</p><h3>Step 3:</h3><pre>SELECT landing_page, second_page, third_page, fourth_page, fifth_page,<br>  <br>COUNT(sessionId) AS Sessions,<br>  <br>ROUND(COUNT(sessionId) / SUM(COUNT(sessionId)) OVER (),2) AS Percentage_of_Sessions</pre><pre>FROM FILTER</pre><pre>GROUP BY 1, 2, 3, 4, 5</pre><pre>ORDER BY 6 DESC</pre><pre>LIMIT  10</pre><p>The final section in Big Query will pull all the page_paths in the Journey, count the total sessions along with the percentage.</p><p>Below is how the final query looks like:</p><pre>WITH<br>  <br>first_five_pages AS ( --- CTE<br>  <br>SELECT<br>    <br>CONCAT(fullVisitorId,&quot;-&quot;,CAST(visitstarttime AS string)) AS sessionId,<br>    <br>h.hitNumber,<br>    <br>h.page.pagePath AS landing_page,<br>    <br>LEAD(h.page.pagePath) OVER (PARTITION BY fullVisitorId, visitstarttime ORDER BY h.hitNumber) AS second_page,</pre><pre>LEAD(h.page.pagePath,2) OVER (PARTITION BY fullVisitorId, visitstarttime ORDER BY h.hitNumber) AS third_page,</pre><pre>LEAD(h.page.pagePath,3) OVER (PARTITION BY fullVisitorId, visitstarttime ORDER BY h.hitNumber) AS fourth_page,</pre><pre>LEAD(h.page.pagePath,4) OVER (PARTITION BY fullVisitorId, visitstarttime ORDER BY h.hitNumber) AS fifth_page,</pre><pre>CONCAT(trafficsource.source,&quot; / &quot;,trafficsource.medium) AS source_medium,</pre><pre>FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`,</pre><pre>UNNEST(hits) AS h<br></pre><pre>WHERE</pre><pre>_table_suffix BETWEEN &#39;20170101&#39;</pre><pre>AND &#39;20170631&#39;</pre><pre>AND totals.visits = 1</pre><pre>AND h.type=&quot;PAGE&quot; ),<br></pre><pre>FILTER AS (</pre><pre>SELECT *</pre><pre>FROM first_five_pages</pre><pre>WHERE hitNumber = 1</pre><pre>AND REGEXP_CONTAINS(source_medium, &#39;google / organic&#39;)</pre><pre>AND landing_page LIKE &#39;/home&#39; )</pre><pre>SELECT landing_page, second_page, third_page, fourth_page, fifth_page,<br>  <br>COUNT(sessionId) AS Sessions,<br>  <br>ROUND(COUNT(sessionId) / SUM(COUNT(sessionId)) OVER (),2) AS Percentage_of_Sessions</pre><pre>FROM FILTER</pre><pre>GROUP BY 1, 2, 3, 4, 5</pre><pre>ORDER BY 6 DESC</pre><pre>LIMIT  10</pre><p>And here’s the resulting table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T1jB3Wh2E_YIf5dE" /></figure><h3>Analyse your findings</h3><p>The last step of this exercise is analyse findings. Following are few potential questions to investigate:</p><ul><li>What are the popular landing pages?</li><li>How many users drop off after visiting the landing page?</li><li>What are the popular second pages in the journey?</li><li>Where are most of the users leaving from?</li></ul><h3>Most Important Point</h3><p>With BigQuery, you can analyse what is happening on your website on a very granular level page by page, sequence of interactions down to a particular session level. Extracting Page Paths is a part of functionality that BigQuery offers.</p><p>With GA4 rolling out the free BigQuery Integrations for all analytics account, it’s perhaps the best time to start utilising it and take your analysis to next level.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c5d76f5aeeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>