-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added adroll pixel script to _app (#534)
* added adroll pixel script to _app * added adRoll ids as env variables and updated aws / docker related files * removed whitespaces from env * cookie banner triggers trackers * init of trackers consents moved to _app Co-authored-by: sebastianPiekarczyk <sebastian@oazoapps.com>
- Loading branch information
Showing
14 changed files
with
115 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import getConfig from 'next/config' | ||
|
||
const { adRollAdvId, adRollPixId } = getConfig()?.publicRuntimeConfig | ||
|
||
export const adRollPixelScript = ` | ||
adroll_adv_id = "${adRollAdvId}"; | ||
adroll_pix_id = "${adRollPixId}"; | ||
adroll_version = "2.0"; | ||
(function(w, d, e, o, a) { | ||
w.__adroll_loaded = true; | ||
w.adroll = w.adroll || []; | ||
w.adroll.f = [ 'setProperties', 'identify', 'track' ]; | ||
var roundtripUrl = "https://s.adroll.com/j/" + adroll_adv_id | ||
+ "/roundtrip.js"; | ||
for (a = 0; a < w.adroll.f.length; a++) { | ||
w.adroll[w.adroll.f[a]] = w.adroll[w.adroll.f[a]] || (function(n) { | ||
return function() { | ||
w.adroll.push([ n, arguments ]) | ||
} | ||
})(w.adroll.f[a]) | ||
} | ||
e = d.createElement('script'); | ||
o = d.getElementsByTagName('script')[0]; | ||
e.async = 1; | ||
e.src = roundtripUrl; | ||
o.parentNode.insertBefore(e, o); | ||
})(window, document); | ||
adroll.track("pageView"); | ||
` | ||
|
||
export function adRollScriptInsert() { | ||
const script = document.createElement('script') | ||
|
||
script.type = 'text/javascript' | ||
script.innerText = adRollPixelScript | ||
|
||
document.head.appendChild(script) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as mixpanel from 'mixpanel-browser' | ||
|
||
import { adRollScriptInsert } from './adroll' | ||
|
||
export const COOKIE_NAMES = ['marketing', 'analytics'] | ||
export const LOCALSTORAGE_KEY = 'cookieSettings' | ||
|
||
export type CookieName = typeof COOKIE_NAMES[number] | ||
|
||
interface Switch { | ||
enable: Function | ||
disable: Function | ||
} | ||
|
||
export const manageCookie: Record<CookieName, Switch> = { | ||
marketing: { | ||
enable: () => adRollScriptInsert(), | ||
disable: () => {}, // no needed since adding adRoll instance to app is 0/1 like | ||
}, | ||
analytics: { | ||
enable: () => mixpanel.opt_in_tracking(), | ||
disable: () => mixpanel.opt_out_tracking(), | ||
// todo: delete user data https://developer.mixpanel.com/docs/managing-personal-data | ||
}, | ||
} | ||
|
||
export function initTrackers() { | ||
const trackingLocalState = localStorage.getItem(LOCALSTORAGE_KEY) | ||
|
||
if (trackingLocalState) { | ||
const state = JSON.parse(trackingLocalState).enabledCookies | ||
COOKIE_NAMES.forEach((cookieName) => { | ||
if (state[cookieName]) { | ||
manageCookie[cookieName].enable() | ||
} else { | ||
manageCookie[cookieName].disable() | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters