Skip to content

Commit

Permalink
feat: explicitly track previous route as referrer in tessen
Browse files Browse the repository at this point in the history
  • Loading branch information
roadlittledawn committed Jul 13, 2021
1 parent a7cefd1 commit 1423aeb
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions packages/gatsby-theme-newrelic/src/utils/page-tracking/tessen.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const warnAboutNoop = (pageView) => {
const canSendPageView = (pageView) =>
pageView && pageView.name && pageView.category;

const trackViaTessen = ({ location }, themeOptions) => {
const trackViaTessen = ({ location, prevLocation }, themeOptions) => {
const env = getResolvedEnv(themeOptions);
const tessenConfig = getTessenConfig(themeOptions);

Expand All @@ -32,6 +32,7 @@ const trackViaTessen = ({ location }, themeOptions) => {
config: tessenConfig,
env,
location,
prevLocation,
});

if (!canTrack()) {
Expand All @@ -43,12 +44,12 @@ const trackViaTessen = ({ location }, themeOptions) => {
// wrap inside a timeout to make sure react-helmet is done with its changes (https://github.com/gatsbyjs/gatsby/issues/11592)
requestAnimationFrame(() => {
requestAnimationFrame(() => {
trackPageView({ config: tessenConfig, env, location });
trackPageView({ config: tessenConfig, env, location, prevLocation });
});
});
};

const trackPageView = ({ config, env, location }) => {
const trackPageView = ({ config, env, location, prevLocation }) => {
const { pageView } = config;
const { name, category, ...properties } = pageView;

Expand All @@ -60,28 +61,30 @@ const trackPageView = ({ config, env, location }) => {

tessen.page(name, category, {
env: env === 'production' ? 'prod' : env,
location: location.pathname,
pathname: location.pathname,
referrer: prevLocation,
...properties,
});
};

const initializeTessenTracking =
({ config, env, location }) =>
(options = {}) => {
if (canTrack() && !initialized) {
initialized = true;
const { segmentWriteKey } = config;
window.Tessen.load(['Segment', 'NewRelic'], {
Segment: {
identifiable: true,
writeKey: segmentWriteKey,
},
});

window.Tessen.identify({});

options.trackPageView && trackPageView({ config, env, location });
}
};
const initializeTessenTracking = ({ config, env, location, prevLocation }) => (
options = {}
) => {
if (canTrack() && !initialized) {
initialized = true;
const { segmentWriteKey } = config;
window.Tessen.load(['Segment', 'NewRelic'], {
Segment: {
identifiable: true,
writeKey: segmentWriteKey,
},
});

window.Tessen.identify({});

options.trackPageView &&
trackPageView({ config, env, location, prevLocation });
}
};

export default trackViaTessen;

0 comments on commit 1423aeb

Please sign in to comment.