Tech Blog

Facebook Icon Twitter Icon Linkedin Icon

AnyMind Group

Facebook Icon Twitter Icon Linkedin Icon

[Tech Blog] AnyCreator’s Link-in-bio analytics with Google Analytics and BigQuery

AnyCreator has recently released a new feature called Link-in-bio which allows influencers and content creators to create and customize their micro website, and use this page as their content hub across social media platforms.

Included in this feature is a Link-in-bio analytics dashboard that tracks the user’s bio page traffic including all clicks, page views, and overall page growth.

Before we proceed, allow me to introduce myself. I am Adean, a back-end developer from the AnyCreator team, and in this article, I will give you an overview of how we manage and track page performance using Google Analytics 4 and BigQuery.

Google Analytics (GA4) and BigQuery Links

Even before Link-in-bio was conceptualized, we’ve already used Google Analytics to track AnyTag web traffic. Using GA4, we can monitor which pages are commonly visited, audience location, and more.

With the same approach, we leverage the GA4 capabilities by creating custom events to be triggered from the assigned elements on the Link-in-bio page. These events can then be monitored in real time from the GA4 dashboard.

// GA4 custom event
gtag('event', 'my_link_redirect', { ... });

The next step is to store this information in a database for easy read access. Fortunately, the Google Cloud platform supports exporting data from GA4 to BigQuery. Below is an outline of how to set up a similar workflow from scratch.

  • Sign in to Google Analytics and head to the Admin page

  • Select the property that you want to export to BigQuery and set up a link

  • Fill in the form and select the BigQuery project where you want to keep the data

  • After 24 hrs, the GA4 will automatically export data to BigQuery at which point the database is now usable

Migrate BigQuery to PostgreSQL

During the early stages of the Link-in-bio feature, we used to directly run queries to BigQuery whenever the user views the analytics dashboard. Unfortunately, the performance was not as promising as expected and we have received some negative feedback about the speed of the page.

As a solution, we added an intermediary process that summarizes the data from BigQuery and records it to PostgreSQL. The flow is as described below.

  • Google Analytics exports data to BigQuery daily. Soon after, cronjob triggers the API which puts a list of influencers on a queue

  • AnyCreator takes the influencer’s latest activities from BigQuery and stores them in PostgreSQL

// fetch events from BigQuery for the given influencer
fun getBioPageEvents(influencerId: InfluencerId, bioUrl: ExternalUrl, dates: List<LocalDate>): List<BigQueryBioPageEvent> {
    val bigQuery = BigQueryOptions.getDefaultInstance().service
    val formattedDates = dates.map { it.format(dateFormat) }

    val viewsQuery = """
        SELECT 
            event_date, 
            event_timestamp, 
            event_name, 
            TO_JSON_STRING(geo) AS geo, 
            TO_JSON_STRING(event_params) AS event_params
        FROM `${bigQueryTable}` 
        CROSS JOIN UNNEST(event_params) AS params
        WHERE 
             ...
            (
                event_name = 'my_link_redirect' AND 
                params.key = 'influencer_id' AND 
                params.value.int_value = @influencerId
            ) AND
            event_date IN UNNEST(@dates)
    """.trimIndent()
    val queryConfig = QueryJobConfiguration
        .newBuilder(viewsQuery)
        .addNamedParameter("linkUrl", QueryParameterValue.string("%$bioUrl%"))
        .addNamedParameter("influencerId", QueryParameterValue.int64(influencerId))
        .addNamedParameter("dates", QueryParameterValue.array(formattedDates.toTypedArray(), StandardSQLTypeName.STRING))
        .build()

    return bigQuery
        .query(queryConfig)
        .iterateAll()
        .map {
            BigQueryBioPageEvent(
                date = LocalDate.parse(it.get("event_date").longValue.toString(), dateFormat),
                timestamp = (it.get("event_timestamp").longValue / 1000L),
                eventName = it.get("event_name").stringValue,
                eventParams = it.get("event_params").stringValue,
                geology = it.get("geo").stringValue
            )
        }
}
  • GraphQL queries will fetch summarized data from PostgreSQL

As a result, the Link-in-bio analytics page performs better than when directly using BigQuery.

Summary

Within the Link-in-bio analytics page, influencers can track page views, clicks, and sessions within a given time. Not only this but there’s also an audience graph that shows a list of countries and cities the traffic is coming from. Lastly, we have a pie graph showing the ratio of click events to each custom element in the bio page.

Feel free to check out this feature in our AnyCreator web and mobile app! Enjoy!

Latest News