How to Send Data to Google Analytics from Multiple Platforms: Get the Technical Details

How to Send Data to GA from Multiple Platforms: Get the Technical Details
Estimated Reading Time: 6 minutes

It’s great that Google Analytics (GA) allows us to track many of our different web platforms, but for a lot of businesses those aren’t the only places where business happens. What if you have sales that happen offline? Perhaps you sell products on Amazon and not on your web property?  Or maybe you sell or have conversions on another site like Etsy or Facebook? Those are great  additional ways to increase revenue and allow for more sale avenues, but they also can decrease the value you get out of your analytics tracking—you have no visibility into whether a user bought something elsewhere. Keeping track of revenue across GA and other platforms where you complete sales can be a lot to juggle. The ideal situation is using one tool to track revenue across all sources, as well as tie in other sales from customers who have been on your web properties thereby saving you a lot of time and remarketing dollars.  

Believe it or not, there are ways to get data from properties which may not be tagged into GA. This will allow you to enrich your GA data and provide a more complete picture into how your web properties are performing. Today I’ll walk you through a technical example of how you might implement this approach using the GA API.

Preparing the data

PriceSpider is a common tool many companies use to enable the sale of their products on other platforms such as Amazon. A widget can be created to place products in various locations and allow the sale through avenues other than your own web property or app. In order to get this data into GA, PriceSpider can dump a file which contains sales data for your widgets. For solutions other than PriceSpider, usually a file dump or an API you can access is required to extract the data.  

When you receive the schema of the API or file, you need to determine which columns contain data you want inside of Google Analytics and which ones might not be data you take action on. Specific to the PriceSpider file drop, there are several extremely important columns which we want to ensure makes it in GA:

  • vci_visitor_id: This contains the google cookie ID so we are able to match users who came from your web property to the user who purchased.
  • currency_code: Contains the currency code so we know the currency of the purchase amount.
  • referrer_url: This can be very helpful as it may provide a lot of insight into where the customer came from before completing the purchase.
  • purchase_amount: Why you would want this seems pretty obvious…
  • product_name or product_sku: Either could be used to identify the product purchased, depending on how you set up PriceSpider.

There are many other columns that may be of importance to your business, but we are only going to focus on the key ones above.  

In order to process this file and get the data into GA, each row is its own transaction and will be processed one row at a time. Using Python, we will want to read in each row and separate out the CSV columns.

with open(priceSpider.csv', 'r') as read_obj:
    csv_reader = reader(read_obj)
    for priceSpiderTransaction in csv_reader:

Now that we have each row separated out as an array, we are able to process each column in the transaction data. You may be thinking that we can just send this to GA, but some of the data needs to be transformed or cleaned up; therefore, review each of the important data columns we discussed above and determine the format needed for Google Analytics. From there, we will create the object that will be sent to GA.

# define each column we need to work with
visitorId = priceSpiderTransaction[0]
# currency code is fine as is
currencyCode = priceSpiderTransaction[1]
referrerUrl = priceSpiderTransaction[2]
purchaseAmount = priceSpiderTransaction[3]
productSku = priceSpiderTransaction[4]
productName = priceSpiderTransaction[5]

# visitor ID needs to be separated to only contain the trailing digits
visitorId = visitorId.split('GA1.2.')[1]
# referrer URL needs to have query parameters stripped
referrerUrl = urlparse.urljoin(referrerUrl, urlparse.urlparse(referrerUrl).path)
# need to build out a host URL as well
hostUrl = "https://" + urlparse.urlparse(referrerUrl).hostname
# purchase amount and sku go in a products array
products = []
products.append({'id': productSku, 'name': productName, 'price': purchaseAmount, 'quantity': 1})

# build the measurement to send to Google Analytics
gaObject = {
    "v": 1,
    "tid": 'UA-XXXX', # GA tracking ID,
    "cid": visitorId,
    "ec": "event_bin_action",
    "ea": "event_buy_now_checkout_complete_eretailer",
    "el": 'TEST RETAILER NAME',
    "t": "event",
    "pa": "purchase",
    'dl' : referrerUrl,
    'dh' : hostUrl, 
    "ti": priceSpiderTransaction[6],  # Transaction ID
    "tr": 0,  # Revenue
    "cu": currencyCode,  # Currency Code
    "cd44": "MeasurementProtocol",
    "products": products,
}


The PriceSpider data does not need a lot of transformation or clean-up. Based on the integration you are trying to implement, it may be more complicated or in some cases even simpler. The last step is to send this object to the GA collection endpoint.


requests.post(
    url="https://www.google-analytics.com/collect",
    params=gaObject
)


Once you receive a response from that POST request, be sure to check for the measurement inside of the GA interface.  

If that verification is successful, you are well on your way to making GA work better for you!  Whether it is PriceSpider or another data set, pushing custom measurements into GA will help to streamline your business and gain valuable analytic insights.

Need help with your data properties?

We've got a team of engineers at the ready.

Author

Facebook
Twitter
LinkedIn
Email
Originally Published: October 7, 2021

Subscribe To Our Newsletter

October 11, 2021
Originally published on October 7, 2021

Other Articles You Will Enjoy

How to Integrate Google Analytics 4 with BigQuery for Enhanced Data Analysis and Reporting

How to Integrate Google Analytics 4 with BigQuery for Enhanced Data Analysis and Reporting

Has your business found that its reporting needs require advanced analysis of your analytics data beyond what is practical in the Google Analytics 4…

4-minute read
Best Practices for Leveraging Custom Insights in Google Analytics 4

Best Practices for Leveraging Custom Insights in Google Analytics 4

What Are Custom Insights? Google Analytics 4 (GA4) offers Custom Insights to detect changes in your data that are important to your team specifically….

3-minute read
Google Tag Best Practices for Google Analytics 4

Google Tag Best Practices for Google Analytics 4

After collaborating with several of my colleagues at InfoTrust including Bryan Lamb, Head of Capabilities, Corey Chapman, Senior Tag Management Engineer, Chinonso Emma-Ebere, Tech…

4-minute read
How Does BigQuery Data Import for Google Analytics 4 Differ from Universal Analytics?

How Does BigQuery Data Import for Google Analytics 4 Differ from Universal Analytics?

All Google Analytics 4 (GA4) property owners can now enable ‌data export to BigQuery and start to utilize the raw event data collected on…

2-minute read
Advanced Analysis Techniques in Google Analytics 4: How to Use AI-Powered Insights and Predictive Analytics for Effective Marketing

Advanced Analysis Techniques in Google Analytics 4: How to Use AI-Powered Insights and Predictive Analytics for Effective Marketing

AI-powered insights and predictive analytics are revolutionary tools reshaping the modern marketing landscape. These advanced analytics techniques, particularly prominent in Google Analytics 4 (GA4),…

8-minute read
Leveraging Custom Dimensions and Metrics in Google Analytics 4 for Content Performance Measurement: Best Practices and Real-World Examples

Leveraging Custom Dimensions and Metrics in Google Analytics 4 for Content Performance Measurement: Best Practices and Real-World Examples

In today’s digital landscape where content reigns supreme, understanding how your audience interacts with your content is paramount for success. For news and media…

5-minute read
How Data Maturity Can Cultivate a Data-Driven Culture

How Data Maturity Can Cultivate a Data-Driven Culture

Data-driven decisions are a buzz topic in Martech. It is essential for C-suite executives to understand and more importantly, use their data to move…

4-minute read
App Install Attribution in Google Analytics 4: What You Need to Know

App Install Attribution in Google Analytics 4: What You Need to Know

App install attribution in Google Analytics for Firebase (GA4) is a feature that helps you understand how users discover and install your app. It…

6-minute read
What Is Consent Mode in Google Analytics 4 and How Does It Work? | A Beginner’s Guide

What Is Consent Mode in Google Analytics 4 and How Does It Work? | A Beginner’s Guide

Consent Mode in Google Analytics 4 (GA4) is a helpful tool for website owners to respect user privacy preferences when it comes to tracking…

3-minute read

Get Your Assessment

Thank you! We will be in touch with your results soon.
{{ field.placeholder }}
{{ option.name }}

Talk To Us

Talk To Us

Receive Book Updates

Fill out this form to receive email announcements about Crawl, Walk, Run: Advancing Analytics Maturity with Google Marketing Platform. This includes pre-sale dates, official publishing dates, and more.

Search InfoTrust

Leave Us A Review

Leave a review and let us know how we’re doing. Only actual clients, please.