Google Analytics package


We need to implement a package that adds the Google Analytics library and sends pageviews and events when the URL changes. Just adding the tracking code is not enough because Frontity works as a SPA.

User Stories

As a Frontity user
I want to add a package to include my tracking code
so that I don’t have to write that logic on my own theme.

Possible solution

It should be noted that there will be more analytics packages and some of them could be used at the same time in a Frontity project.

import { sendPageview, sendEvent, afterCSR } from "@frontity/analytics";
import GoogleAnalytics from "../types";

const googleAnalytics: GoogleAnalytics = {
  actions: {
    analytics: {
    ga: {
      sendPageview: ({ state }) => pageview => {
        // Do something with that pageview.
        console.log(, pageview);
      sendEvent: ({ state }) => event => {
        // Do something with that event.
        console.log(, event);
  state: {
    analytics: {
      namespaces: ["ga"]
    ga: {
      trackingId: "UA-123456-7"

export default googleAnalytics;

A post was merged into an existing topic: The analytics library

@david I think your last post belongs to The `analytics` library instead?

You are right. Actually, the Analytics feature discussion was open the very same day this was posted so it had to be a mistake.

Should I move the post to the other FD?
Is that possible, or do I have to copy and paste in the other thread?

I think it’s possible. Try it out and let us know :slightly_smiling_face:

5 posts were split to a new topic: Add Google analytics to my Frontity project