Tracking clicks are registered as page views


#1

I’ve included Snowplow tracking on a basic static site but when I click on a link it’s showing in the network tab as a page view.

Is this a bug or user error?

Below is the static HTML to reproduce:

<!doctype html>
<html lang="en">
<head>
        <!-- Snowplow starts plowing -->
        <script type="text/javascript">
            ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
                p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
                };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
                n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","http://d1fc8wv8zag5ca.cloudfront.net/2.9.2/sp.js","snowplow"));
    
            window.snowplow('newTracker', 'cf', 'app.snowplow-collector.com/', { // Initialise a tracker
                appId: 'app-name',
                cookieDomain: 'app-domain',
                forceSecureTracker: true
            });
    
            window.snowplow('enableActivityTracking', 30, 10);
            window.snowplow('trackPageView');
            window.snowplow('enableLinkClickTracking', null, true, true);
            window.snowplow('refreshLinkClickTracking');
        </script>
        <!-- Snowplow stops plowing -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="shortcut icon" href="favicon.ico">
  <title>Application</title>
</head>
<body>
<a href="" class="tracked">TEST</a>
<div id="root"></div>
</body>
</html>

This is the AJAX request that happens:

https://app.snowplow-collector.app.io//i?stm=1534773418079&amp;e=pv&amp;url=file%3A%2F%2F%2FUsers%2Fdarren.haken%2Fworkarea%2Ftmp%2Fsnowplow-tracker%2Findex.html&amp;page=Metrics%20Triage&amp;tv=js-2.9.2&amp;tna=cf&amp;aid=APP&amp;p=web&amp;tz=Europe%2FLondon&amp;lang=en-US&amp;cs=UTF-8&amp;f_pdf=1&amp;f_qt=0&amp;f_realp=0&amp;f_wma=0&amp;f_dir=0&amp;f_fla=1&amp;f_java=0&amp;f_gears=0&amp;f_ag=0&amp;res=2560x1440&amp;cd=24&amp;cookie=1&amp;eid=dcccabf4-e7f5-43f3-8999-d86e5d034686&amp;dtm=1534772950317&amp;vp=2520x1306&amp;ds=2520x1306&amp;vid=1&amp;sid=aea647a5-5494-42dd-94ba-9f6b2291357f&amp;duid=eb453020-cbed-4e2b-8538-1f0d2980b821&amp;fp=3185976282


#2

Hi @darrenhaken,

From memory, I think the issue will be resolved by calling the ‘enableLinkClickTracking’ method before ‘trackPageView’.

What you’re seeing is likely the page view for the next page as opposed to the Link click itself. You should see both events.

window.snowplow('enableLinkClickTracking', null, true, true);
window.snowplow('enableActivityTracking', 30, 10);
window.snowplow('trackPageView');

Let us know how you get on!


#3

Hi @Colm

My JS is in this order:

window.snowplow('enableActivityTracking', 30, 10);
            window.snowplow('enableLinkClickTracking', null, true, true);
            window.snowplow('refreshLinkClickTracking');
            window.snowplow('trackPageView');

It still seems to be firing a pv when I click the link.

Any ideas?


#4

@Colm I tried the order you suggested as well and it still didn’t work


#5

@colm any other ideas?


#6

@darrenhaken, is your link dynamically generated and is not available on page load? Why would you call refreshLinkClickTracking there? Did you mean to call it when the link is available? Its usage would follow some code ensuring the link has been rendered on the page. It’s not happening as far as I can see.


#7

@ihor This is my first time using Snowplow so it’s me being unfamiliar with the API.

I amended it to:

window.snowplow('newTracker', 'cf', 'localhost:8080', { // Initialise a tracker
                appId: 'app-id',
            });
            window.snowplow('enableLinkClickTracking');

I ran this against a local collector and I am now seeing an event fired when clicking the Link in the original HTML sample. The event is being tracked as a Self Describing Event is this correct?

I have used the Chrome extension to see the event


#8

@darrenhaken, yes, link click event is implemented as self-describing events under the hood. Here’s its table definition if you are to load the data into Redshift: https://github.com/snowplow/iglu-central/blob/master/sql/com.snowplowanalytics.snowplow/link_click_1.sql.


#9

Hi @darrenhaken,

Your example seems to work (except extra / in collector url). Note, you have empty href, so you are in fact refreshing your page. As an effect you get PageView, Unstructured event (link click), PageView sequence. Most likely you do not preserve history (which is being cleaned after page reload).

Cheers,
GE


#10

I got this working thanks to you both for all the help