Skip to main content

Log campaign events to Google Analytics

Updated over 2 weeks ago

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. From there, you can trigger GA4 events based on the Triggerbee Campaign Events.


Log all campaign events to GA4

The first thing you need to do is to configure the campaign events that will accept the scripted events later on.
​
Navigate to Admin > Property > Events > Create event in your GA4 account. We recommend logging 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, closed etc., but those are usually not as relevant as clicks and submissions.

Step One: Create a Custom Event

Go to Admin > Property > Events > Create event. Add a Custom event name and a matching condition, eg. tb_campaign_click.
​
Here is an example of an event in GA4 that will track campaign clicks.

Step Two: Create a custom dimension for Campaign Name.

Navigate to Admin > Data display > Custom definitions > Create Custom Dimension

Step Three: Push the campaign events to GA4

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

Sometimes, it is also useful to track specific button clicks. The general campaign tracking will automatically grab the campaign name for any clicks happening, but if you have multiple buttons - they will get the same naming. In those cases, you could also add tracking to the specific buttons.

To do so, navigate to the button in your campaign and go to Actions. Enter this example script and adjust according to your setup:

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.

Did this answer your question?