Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

feat(tracking): track segmentID if cookie is present #358

Merged
merged 1 commit into from Aug 22, 2016

Conversation

keithamus
Copy link
Contributor

@keithamus keithamus commented Aug 19, 2016

This change detects if the segmentID cookie is present, and, if so, adds it to the o-tracking context object, so that it is tracked for all events on the page. segmentID is set as a session cookie, and is not always present.

segmentID is used for campaign tracking for inbound ads, through - for example - facebook ads. We need to track segmentID so we can attach anonymous user journeys to particular campaigns.

Based on git blame data, I'm going to ping @wheresrhys, @GlynnPhillips and @commuterjoy for anyone who fancies reviewing. I'm also going to ping @ironsidevsquincy @matthew-andrews who I've spoken to about the requirements for this. @matthew-andrews also suggests @i-like-robots as a potential reviewer.

@wheresrhys
Copy link
Contributor

Looks OK to me. You may want to check that the segID also gets added to tracking of any click events etc (not sure if that falls through automatically from oTracking init)

@wheresrhys
Copy link
Contributor

👍

@@ -64,6 +64,9 @@ const oTrackingWrapper = {

const edition = document.querySelector('[data-next-edition]') ? document.querySelector('[data-next-edition]').getAttribute('data-next-edition') : null;
context.edition = edition;
if (/(?:^|;)\s*segmentID=([^;]+)/.test(document.cookie)) {
context.segmentID = RegExp['$1'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh, didn't know about this. Is it safe? (just going by the big 'Non-standard' warning at the top of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll refactor.

This change detects if the `segmentID` cookie is present, and, if so, adds it to the o-tracking context object, so that it is tracked for all events on the page. segmentID is set as a session cookie, and is not always present.

segmentID is used for campaign tracking for inbound ads, through - for example - facebook ads. We need to track segmentID so we can attach anonymous user journeys to particular campaigns.
@keithamus keithamus merged commit f57ccc8 into master Aug 22, 2016
@keithamus keithamus deleted the track-segment-id branch August 22, 2016 11:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants