Tracking Events With Google Tag Manager


#1

Hi,

I’m trying to record events in google analytics, as prospects move through my decision tree.

I want to run a small script at the exit of each node to track their progression:

<script>
    ga('send', 'event', 'decision tree', 'next', 'name',);
</script>

However, I get an error:

Uncaught ReferenceError: ga is not defined

I was reading here, a google group article about the issue. Apparently, it’s related to using GTM to implement google analytics.

But, I’m hesitant to implement UA, manually, because various configurations, provided in the customer GTM container, help with cross domain tracking.


#2

I found this video, from MeasureSchool:

But, I’m wondering if you have a specific way of implementing, that recommend when using LH?


#3

Hi @Wynne_Pirini,

How are you?

I’m assuming you’ve been through these steps and integrated GTM as shown here:

We take care of cross domain tracking. Our GTM integration adds a bunch of extra TAGs etc to take care of cross domain tracking. This is the most stable and scalable implementation we’ve found. I believe it’s a derivative of Simo Ahava which we edited.

If yes, then it’s pretty easy. On the tracking node, simply add this the script you’re looking at follows…

<script>
ga(‘send’, {
hitType: ‘event’,
eventCategory: ‘DT:QualDT’,
eventAction: ‘Qn:Telling a story about open-mindedness is a powerful strategy to get people to accept new ideas.’,
eventLabel: ‘Ans:{ga_1}’
});
</script>

Notice: {ga_1} is a custom field. Save your answers into a custom field and add that custom field to the event.


#4

Hey Nik,

I’m good thanks :slight_smile:

I’ve used your LH cross-domain GTM container, and followed the instructions in your training, to set it up.

When I run the ga script, I get error:

Uncaught ReferenceError: ga is not defined

Wynne


#5

Hi @Wynne_Pirini,

Time to dive into code :slight_smile:

Which decision tree?

Nik


#6

Hi Nik,

lol.

The decision tree is TE 10min call questionnaire

I’ve got the events script running on the first node.

Cheers,
Wynne


#7

Wynne,

Problem is resolved?

BTW, we have these “secret” custom fields so you don’t have to manually type in values from each node… :slight_smile:

Added to article:

Example:
<script>
ga(‘send’, {
hitType: ‘event’,
eventCategory: ‘{_c_dt}’,
eventAction: ‘{_c_question}.’,
eventLabel: ‘{_c_answer}’
});
</script>

Current Decision Tree Title: {_c_dt}:
Current Node Title: {_c_node}
Question: {_c_question}
Answer: {_c_answer}


#8

Hi Nik,

Thanks for the knowledgebase article and dynamically inserted tokens - definitely saves time :slight_smile:

And, great seeing how to visualise the funnel in google analytics, too.

I’m still getting the error. On this page - REMOVED- I’m getting this error showing up:

CloudApp


#9

Wynne,

Sent a support ticket email with link to video review.

Please check your email.

Nik