Skip to content

Commit

Permalink
chore: add Heap analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Barnett authored and Peter Barnett committed Sep 18, 2024
1 parent 461933a commit 36adbc8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {AppState} from 'src/types'
// Utils
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
import {CLOUD} from 'src/shared/constants'
import {executeVWO} from 'src/utils/vwo'
import {executeVWO, executeHeap} from 'src/utils/analyticsTools'

// Providers
import {UserAccountProvider} from 'src/accounts/context/userAccount'
Expand All @@ -57,14 +57,14 @@ const App: FC = () => {
if (CLOUD && isFlagEnabled('rudderstackReporting')) {
try {
load(RUDDERSTACK_WRITE_KEY, RUDDERSTACK_DATA_PLANE_URL)
} catch (error) {
} catch (err) {
console.error(
'Error loading Rudderstack with wk: ',
RUDDERSTACK_WRITE_KEY,
' at: ',
RUDDERSTACK_DATA_PLANE_URL
)
reportErrorThroughHoneyBadger(error, {
reportErrorThroughHoneyBadger(err, {
name: 'Rudderstack Loading Function',
})
}
Expand Down Expand Up @@ -104,6 +104,16 @@ const App: FC = () => {
}
}

if (CLOUD && isFlagEnabled('heapAnalytics')) {
try {
executeHeap()
} catch (err) {
reportErrorThroughHoneyBadger(err, {
name: 'Unable to load Heap Analytics',
})
}
}

setAutoFreeze(false)
}, [])

Expand Down
53 changes: 53 additions & 0 deletions src/utils/vwo.ts → src/utils/analyticsTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,56 @@ export const executeVWO = () => {
return code
})()
}

export const executeHeap = () => {
;(window.heapReadyCb = window.heapReadyCb || []),
(window.heap = window.heap || []),
(heap.load = function (e, t) {
;(window.heap.envId = e),
(window.heap.clientConfig = t = t || {}),
(window.heap.clientConfig.shouldFetchServerConfig = !1)
var a = document.createElement('script')
;(a.type = 'text/javascript'),
(a.async = !0),
(a.src = 'https://cdn.us.heap-api.com/config/' + e + '/heap_config.js')
var r = document.getElementsByTagName('script')[0]
r.parentNode.insertBefore(a, r)
var n = [
'init',
'startTracking',
'stopTracking',
'track',
'resetIdentity',
'identify',
'getSessionId',
'getUserId',
'getIdentity',
'addUserProperties',
'addEventProperties',
'removeEventProperty',
'clearEventProperties',
'addAccountProperties',
'addAdapter',
'addTransformer',
'addTransformerFn',
'onReady',
'addPageviewProperties',
'removePageviewProperty',
'clearPageviewProperties',
'trackPageview',
],
i = function (e) {
return function () {
var t = Array.prototype.slice.call(arguments, 0)
window.heapReadyCb.push({
name: e,
fn: function () {
heap[e] && heap[e].apply(heap, t)
},
})
}
}
for (var p = 0; p < n.length; p++) heap[n[p]] = i(n[p])
})
heap.load('1919519062')
}

0 comments on commit 36adbc8

Please sign in to comment.