Log campaign events to Google Analytics

This article will describe three different ways of working with campaign follow-up in Google Analytics. 

By listening to Triggerbee Onsite Campaign events, data can be sent to Google Analytics when a campaign is opened (eg. visitor viewed the campaign), a campaign is closed, submitted etc. All Triggerbee events and event data that you can use can be found here.

If you prefer working with Google Analytics through Google Tag Manager, check out this article about how to add the campaign events and campaign data to GTM.

Log all campaign events to GA4

Before you trigger any events, you need to configure them in your GA4 account under Admin > Property > Events > Create event. We recommend the following events and custom dimensions:

  • Events: "tb_campaign_click" and "tb_campaign_form_submission"
  • Custom dimension: "campaign_name" (which will contain the campaign name)

There are also events for campaigns viewed and closed etc., but those are usually not as relevant as click and submissions.

Create Custom Event

Admin > Property > Events > Create event. Here is an example of an event in GA4 that will track campaign clicks.

Create a custom dimension for Campaign Name.

Admin > Data display > Custom definitions > Create Custom Dimension

Once the events and dimensions are created in GA4, you'll need to add a script that sends them from Triggerbee to GA4. Below is an example of a script that tracks clicks and form submissions in GA4. Replace 'YOUR-GA4-TRACKING-ID' with your GA4 tracking ID and paste the script into your Triggerbee client script or wherever it fits best in your setup.

window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());

gtag('config', 'YOUR-GA4-TRACKING-ID');

document.addEventListener("onTriggerbeeWidgetClicked", function (event) {     
    gtag('event', 'tb_campaign_click', {
        'campaign_name': event.detail.campaignName
    });
});

document.addEventListener("onAfterTriggerbeeFormSubmitted", function (event) {     
    gtag('event', 'tb_campaign_form_submission', {
        'campaign_name': event.detail.campaignName
    });
});

Note: The events will only be visible in the statistics once they have been triggered on the site.


Logging specific click events to GA4

Log specific click events on buttons in your campaign. Navigate to your button > Go to Actions and enter the adjusted script as an additional action. See example below.

gtag("event", "tb_campaign_click", {
    currency: "USD",
    value: 30.03,
    coupon: "SUMMER_FUN",
    payment_type: "Credit Card",
    items: [
      {
        item_id: "SKU_12345",
        item_name: "Stan and Friends Tee",
      }
    ]
  });

Using UTM links as tracking

Inside the Triggerbee Onsite Campaign Editor, GA tracking can also be added via UTM links on specific clicks. Just add your UTM-tracking to the URL you want the button or widget to link to.


Log all campaign events in GA

Here is an example on how to track clicks and form submissions (including survey responses):

document.addEventListener("onTriggerbeeWidgetClicked", function (event) {
	ga('send', 'event', {
		eventCategory: 'Triggerbee',
		eventAction: 'Campaign Clicked',
		eventLabel: event.detail.campaignName
	});
});

document.addEventListener("onAfterTriggerbeeFormSubmitted", function (event) {
	ga('send', 'event', {
		eventCategory: 'Triggerbee',
		eventAction: 'Campaign Form Submission',
		eventLabel: event.detail.campaignName
	});
});

Logging specific click events to GA

Inside the Triggerbee Onsite Campaign Editor, scripts can also be added to execute on specific clicks. This is especially useful when having several buttons or multiple action points in your campaign. The general onTriggerbeeWidgetClicked event that is explained above will aggregate any clicks in every campaign you publish, but with button scripts - each button can have its own tracking.

This is done by adding the full GA tracker event (in the example above), or - if you want to minimize code, using the short version, eg: 

ga('send','event','Triggerbee','Button Clicked','Winter Campaign');

Note: The script snippet is only an example. It needs to be adjusted to fit your Google Analytics setup.

Still need help? Contact Us Contact Us