Code Monkey home page Code Monkey logo

Comments (3)

philipwalton avatar philipwalton commented on June 9, 2024

This is possible, but you'll have to add a bit of code to make it work.

What you want to look at is the hitFilter option, which allows you to programmatically modify any hit prior to it being sent, and in the case of hits that are the result of user interaction with a DOM element, that element gets passed to the function as well.

Here's a basic example of how you could do what you're asking (note: you might have to modify it to work with your setup):

ga('require', 'eventTracker', {
  hitFilter: function(model, element) {
    // Only sets the event label as the link `href` for clicks on elements
    // with an `href` property.
    if (element.href) {
      // Make sure to set the third parameter to `true` so this value only
      // gets sent with the current hit.
      // https://developers.google.com/analytics/devguides/collection/analyticsjs/model-object-reference#set
      model.set('eventLabel', element.href, true);  
    }
  }
});

from autotrack.

ilarumk avatar ilarumk commented on June 9, 2024

One issue I am seeing is
when I console.log, element in hitFilter, I get

...

It doesn't return all the links under the div or unable to find which link is actually clicked.

Options for me are
Add all the link in above div into event listeners and check if link is clicked and add use that in hitFilter.

I am doing this on different div's
eg. is

<div class="xyz" data-on="click" data-event-category="blog" data-event-action="click">
    <div class="col-md-12">
        <h3 class="text-primary today BlogListHeader">Blog & News</h3>
    </div>
    <div class="BlogList">
            <div class="col-md-12">
    <div class="row">
    <div class="blogitem">
        <div class="col-xs-4 col-md-5">
        <a href="http://test.com.au/"><img class="img-responsive" src="seating_74ced3b40ec351b7700e96378f870fa1_w320_r1.6.jpg" alt="" /></a>
        </div>
        <div class="col-xs-8 col-md-7 no-pd-lft">
        <div class="headline">
            <b><a href="http://test.com.au/">A Look Inside</a></b>
        </div>
                <div class="description">What you can expect from the renowned Airlines</div>
                </div>
</div>
</div>

from autotrack.

philipwalton avatar philipwalton commented on June 9, 2024

The element variable isn't going to reference the links within the div because you put the data-* attributes on the div itself. The eventTracker plugin isn't specific to links, it can be used with any type of element.

from autotrack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.