How can I create a GA event when a specific site loads with some specific content?

Gold Contributor
Gold Contributor

I'd like to fire a GA event whenever a site (www.example.com/example) is loaded and contains a certain element (the class "sucess-msg").

 

I imagine writing something like:

 

if(document.getElementsByClassName("success-msg").length){

_gaq.push([...])

}

 

What extension can I use for that? How do I set it up to only be active on a specific site?

 

Thanks

3 REPLIES 3

How can I create a GA event when a specific site loads with some specific content?

Employee Emeritus

Hi Mohamed,

 

You can use the utag.link call. You can implement this using the JavaScript Code extension and scope it to DOM Ready. It would look something like the following:

 

if (b['dom.url'] === 'http://www.example.com/example' && document.getElementsByClassName("success-msg").length))

{

utag.link( { event_category:"button", event_action:"click" } );

}

How can I create a GA event when a specific site loads with some specific content?

Tealium Employee
For anyone interested in the answer, check the comment attached to this question.

How can I create a GA event when a specific site loads with some specific content?

Gold Contributor
Gold Contributor
Thanks, Meng Lim.
Public