Skip to content

Commit

Permalink
Track when story is scrolled to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Aug 28, 2018
1 parent 6e3cc3a commit d9ef164
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/StoryView/Body.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Container } from 'reactstrap';
import VisibilitySensor from 'react-visibility-sensor';
import SocialShare from './SocialShare';
import { GTAGTracker } from '../../lib/gtag';

const createMarkup = html => ({ __html: html });

class StoryViewBody extends React.Component {
constructor(props) {
super(props);
this.trackEndOfContent = this.trackEndOfContent.bind(this);
}

/**
*
*/
Expand All @@ -22,6 +28,11 @@ class StoryViewBody extends React.Component {
});
}

trackEndOfContent(isVisible) {
const { tracker } = this.props;
if (isVisible) tracker.trackEndOfContent();
}

/**
*
*/
Expand Down Expand Up @@ -104,6 +115,7 @@ class StoryViewBody extends React.Component {
/>
{/* eslint-disable-next-line react/no-danger */}
<div id={`body-${storyId}`} className="fr-view" dangerouslySetInnerHTML={createMarkup(body)} />
<VisibilitySensor onChange={this.trackEndOfContent} />
<hr className="mt-4 mb-4" />
<SocialShare
title={title}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/gtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export const trackOutboundLink = (url, props) => {
});
};

export const trackEndOfContent = (props) => {
trackEvent('scroll_to_bottom', {
...props,
event_category: 'engagement',
value: 1,
});
};

export class GTAGTracker {
constructor(config = {}, enabled = true) {
this.config = config;
Expand All @@ -53,4 +61,8 @@ export class GTAGTracker {
outboundLink(url) {
if (this.enabled) trackOutboundLink(url, this.config);
}

trackEndOfContent() {
if (this.enabled) trackEndOfContent(this.config);
}
}

0 comments on commit d9ef164

Please sign in to comment.