Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add Heap analytics #6951

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
}