how to do reverse ETL with GA4?
# support
f
how to do reverse ETL with GA4?
g
I assume that you plan to send data from your warehouse to GA4. So that means, you need to 1. add your warehouse as a source 2. add GA4 as destination are you facing any issues in doing that?
f
sorry, for my missunderstanding
how RD can send from my warehouse to GA4?
my main concern is that i need a bare minimum for my business teams, to delete GA script aand now i have this
Sending at the same time the event to BQ and GA4, in GA4, events are not associated to the page.... i have no page durations...
this is not working for me
g
Ok. Can you share how do your connections look like? sources, destinations
f
take into account that i am "learnign" with a small site, but my idea is to work with you with my company
we have near 50 millions per month
events
ok, i will share with you
we are using this
in BQ and with DBT i created some models based in your repos in gihub
rudder_1 is what we send from JS script
this is what we create with dbt and you repos
g
Got it. Do you see the events in the live events tab?
f
let trackedSet = []; let formsToNotTrack = []; let rdTracker = { hasClickedOnLink: false, isAboutToRefresh: false, hasMouseLeftWindow: false, hasInactivityTracked: false, }; const linksToTrack = document.querySelectorAll("a[href]"); linksToTrack.forEach(link => { if ( trackedSet.includes(link) ) { return ; } const href = link.getAttribute("href"); if ( !href || href === "javascript:void(0)" ) { return ; } link.addEventListener("click", event => { event.preventDefault(); trackThisLink(link); }); trackedSet.push(link); }); function trackThisLink(link) { if ( !link ) { return ; } let linkData = {}; let href = link.getAttribute("href"); if ( /^#/.test(href) ) { linkData = intraLinkData(link); } else { if ( /^\//.test(href) ) { linkData = interLinkData(link); } else { href = new URL(href); if ( href.origin === window.location.origin ) { linkData = interLinkData(link); } else { linkData = externalLinkData(link); } } } sendTrackedLinkData(link, linkData); } function intraLinkData(link) { const href = link.getAttribute("href"); const title = getLinkElementTitle(link); return { "type": "intra", "linkTitle": title, "destinationId": href, "meta": { "id": link.getAttribute("id") || "", "classes": link.getAttribute("class") || "", "_parent": { "id": link.parentElement.getAttribute("id") || "", "classes": link.parentElement.getAttribute("class") || "", }, }, }; } function getLinkElementTitle(link) { let title = link.getAttribute("title"); title = title || link.textContent; const img = link.querySelector("img"); if ( img ) { title = title || img.getAttribute("alt"); } title = title || "N/A - Link text is unknown"; return title.trim(); } function interLinkData(link) { const href = link.getAttribute("href"); const title = getLinkElementTitle(link); const newTab = link.getAttribute("target") === "_blank"; return { "type": "internal", "linkTitle": title, "destination": href, "destinationPath": new URL(href, window.location.origin).pathname, "newTab": newTab, "meta": { "id": link.getAttribute("id") || "", "classes": link.getAttribute("class") || "", "_parent": { "id": link.parentElement.getAttribute("id") || "", "classes": link.parentElement.getAttribute("class") || "", }, }, }; } function externalLinkData(link) { const href = link.getAttribute("href"); const title = getLinkElementTitle(link); const newTab = link.getAttribute("target") === "_blank"; const relAttribute = link.getAttribute("rel").toLowerCase(); return { "type": "external", "linkTitle": title, "destination": href, "destinationOrigin": new URL(href).origin, "newTab": newTab, "isNoFollow": relAttribute.includes("nofollow"), "isSponsored": relAttribute.includes("sponsored"), "isNoReferer": relAttribute.includes("noreferer"), "meta": { "id": link.getAttribute("id") || "", "classes": link.getAttribute("class") || "", "_parent": { "id": link.parentElement.getAttribute("id") || "", "classes": link.parentElement.getAttribute("class") || "", }, }, }; } function sendTrackedLinkData(link, linkData) { try { rudderanalytics.track( 'linkClicked', linkData, simulateLinkClick(link) ); } catch(_) { simulateLinkClick(link); } } function simulateLinkClick( link ) { if ( link.href ) { link.target === '_blank' ? window.open(link.href, '_blank') : window.location.href = link.href; } } window.addEventListener("scroll", function(_) { var h = document.documentElement, b = document.body, st = 'scrollTop', sh = 'scrollHeight'; var percent = (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100; if (percent >= 24.99 && !trackedSet.includes('scrolled-25')) { trackScrollEvent('scrolled-25'); } else if (percent >= 49.99 && !trackedSet.includes('scrolled-50')) { trackScrollEvent('scrolled-50'); } else if (percent >= 74.99 && !trackedSet.includes('scrolled-75')) { trackScrollEvent('scrolled-75'); } else if (percent >= 99.00 && !trackedSet.includes('scrolled-100')) { trackScrollEvent('scrolled-100'); } }); function trackScrollEvent(eventName) { try { rudderanalytics.track( eventName, {} ); } catch(_) {} finally { trackedSet.push(eventName); } } window.onload = function() { var trackDates = { 'datePublished': '', 'dateModified': '' }; document.querySelectorAll("script[type='application/ld+json']") .forEach(function(script) { var jsonString = script.innerHTML; var json = JSON.parse(jsonString); if ( json ) { if ( json.hasOwnProperty("dateModified") ){ trackDates['dateModified'] = json['dateModified']; } if ( json.hasOwnProperty('datePublished') ) { trackDates['datePublished'] = json['datePublished']; } } }); rudderanalytics.page( document.title, trackDates ); if ( !sessionStorage.tabID ) { sessionStorage.tabID = Math.floor(Math.random() * 10e9); } const url = window.location.protocol + '//' + window.location.host + window.location.pathname; const hashedUrl = Math.abs(hashString(url)); let pageHistoryStack = sessionStorage.getItem("pageHistory") || '[]'; pageHistoryStack = JSON.parse(pageHistoryStack); let pageHistoryStackSize = sessionStorage.getItem("pageHistoryStackSize") || "0"; pageHistoryStackSize = parseInt(pageHistoryStackSize); if ( pageHistoryStack.length <= 0 ) { beginUserJourney(); pageHistoryStack.push(hashedUrl); } else { trackUserEnRoute( pageHistoryStackSize > pageHistoryStack.length ); if ( pageHistoryStack[pageHistoryStack.length - 1] !== hashedUrl ) { pageHistoryStack.push(hashedUrl); } } sessionStorage.setItem("pageHistory", JSON.stringify(pageHistoryStack)); sessionStorage.setItem("pageHistoryStackSize", pageHistoryStack.length); }; function hashString(str) { return str.split('').reduce((prevHash, currVal) => (((prevHash << 5) - prevHash) + currVal.charCodeAt(0))|0, 0); } function beginUserJourney() { const url = window.location.protocol + '//' + window.location.host + window.location.pathname; setTimeout( function() { rudderanalytics.track( "userJourneyStarted", { anonymousId: rudderanalytics.getAnonymousId(), prevPage: "", currPage: window.location.href, sessionTabId: sessionStorage.tabID, } ); sessionStorage.setItem("currPage", url); }, 500 ); } function trackUserEnRoute( userClickedBack = false ) { const url = window.location.protocol + '//' + window.location.host + window.location.pathname; setTimeout( function() { rudderanalytics.track( "userEnRoute", { anonymousId: rudderanalytics.getAnonymousId(), prevPage: sessionStorage.getItem("currPage") || "", currPage: window.location.href, clickedBack: userClickedBack, sessionTabId: sessionStorage.tabID, }, function() { console.log("enRouteTracked:"); } ); sessionStorage.setItem("currPage", url); }, 500 ); } document.addEventListener('keydown', function(event) { if ( event.which == 116 || ( event.which == 82 && event.ctrlKey ) ) { rdTracker.isAboutToRefresh = true; } }); window.onbeforeunload = function() { let triggeredBy = document.activeElement; if ( triggeredBy.hasAttribute("href") && ( /^\//.test( triggeredBy.getAttribute("href") ) || triggeredBy.getAttribute("href").startsWith(window.location.origin) ) && !rdTracker.isAboutToRefresh && !rdTracker.hasMouseLeftWindow ) { // Do nothing at this point } else { let pageHistoryStack = sessionStorage.getItem("pageHistory") || '[]'; pageHistoryStack = JSON.parse(pageHistoryStack); if ( pageHistoryStack.length > 0 ) { pageHistoryStack.pop(); sessionStorage.setItem("pageHistory", JSON.stringify(pageHistoryStack)); } } } document.addEventListener('copy', function(event) { var selectedText = window.getSelection().toString(); selectedText = selectedText.replace(/\u200B/g, ""); rudderanalytics.track( "copiedToClipboard", { sessionTabId: sessionStorage.tabID, clipboardText: selectedText, } ); }); document.querySelectorAll('form') .forEach(function(form) { form.addEventListener('submit', function(event) { var formId = form.getAttribute('id') || ''; if ( formsToNotTrack.includes(formId) ) { return ; } event.preventDefault(); rudderanalytics.track( "formSubmit", { sessionTabId: sessionStorage.tabID, formId: formId, formAction: form.getAttribute('action') || '', } ); setTimeout(function() { HTMLFormElement.prototype.submit.call(form); }, 1000); }); }); document.querySelectorAll('input[type=radio], input[type=checkbox') .forEach(function(input) { input.addEventListener('change', function() { rudderanalytics.track( "radioCheckboxChanged", { sessionTabId: sessionStorage.tabID, inputId: input.getAttribute('id') || '', inputName: input.getAttribute('name') || '', isChecked: input.checked, } ); }); });
g
Or just check the events tab to see if you're receiving the events from the source or not
f
this is my analytics.js
what we build to send events to GA4 and BQ
g
Can you please check the events tab of your JS source
Go to JS source in your rudderstack account -> click events tab
what do you see there?
f
ok
userJourneyStarted 235 26 minutes ago scrolled-25 187 24 minutes ago scrolled-50 141 29 minutes ago scrolled-75 102 28 minutes ago linkClicked 62 30 minutes ago scrolled-100 52 27 minutes ago userEnRoute 45 an hour ago copiedToClipboard 14 14 minutes ago formSubmit 6 9 hours ago
this
this is what i have in a GA4 account
and this is what i have with RD
so , in ordert to be able to delete scripts and that my business team can use GA4 as before
i need some help
i am blocked here
g
This last image does show that you are getting events in your GA4.
f
yes , i am getting events
g
ok
f
but it is very different that what i need to be able to. follow a customer journey
tracking clics, et...
g
what do you mean by that?
f
Pradeep
if my team is accostumated
to use GA4
with this info i cannot do anything
only pagesviews...
no duration...
i cannot see in what page is the event done
i cannot track sessions.
i need to track a session, from 0 to 100
g
Ok. So you want to add more types of events than just page views and link clicks?
f
from user lands in my site to user leave teh site
no
i already added pagevies,
clics
forms...
but i cannot do anything with that in GA4
if you want i can add you to this GA4
if you give me an email
nd you can see
i cannot make a funnel
it not ok for me
g
Ok. So you are receiving the events via RudderStack. And now you want to utilize those events to create some funnels and reports in Google Analytics.
f
0,00 s
this is with a real GA4
so i need to get the same
through events i sent from RD
this is my problem
i dont know if i need to make some dbt and reverse ETL from BQ to GA4 , or whatever
g
No. This is not needed.
f
then what i am doing wrong
i shared with you my analytics.js
g
You're not doing anything wrong as far as I can see. The only part remaining for you is to utilize these events the way you want them. I see you want to do two things 1. Create funnels - For this, please search Google Analytics support forum (as I think you don't need to do anything on RudderStack side for this when your events are already reaching GA4) 2. Get session duration info in GA4 - @shy-kite-21035 is there anything to do at RudderStack side to get session duration in GA4?
Understand that RudderStack is only helping you to send events from your website to Google Analytics. How you use those events is upto you.
f
If you want a customer that wants to substitute ga4 with yout solution
You neeed to give support
This is an end to end service
If I cannot do wha t I need
It is been difficult to sell me
g
Do you want to remove Google Analytics from your data stack completely?
f
Yes, this is the idea
i wnat to remove all the scripts in ours sites
hubspot, GA4, amplitude
and to send the events from RD
if not, RD makes no sense for me... it another script
g
You are already there. Your events are flowing from website to GA4
f
do you understand my point now?
in my compnay yes,
but i am learnign your product with a personal site
g
If you set up all those events that you had earlier, you are good to remove GA script from your webiste
f
and removed GA4
and now i sent events to GA4
from RD
with a custom js i built
that is my point
i need your support to see if with this custom tracking js
is ok to get the same info in GA4
that i had before
let trackedSet = [];
let formsToNotTrack = []; let rdTracker = { hasClickedOnLink: false, isAboutToRefresh: false, hasMouseLeftWindow: false, hasInactivityTracked: false, }; const linksToTrack = document.querySelectorAll("a[href]"); linksToTrack.forEach(link => { if ( trackedSet.includes(link) ) { return ; } const href = link.getAttribute("href"); if ( !href || href === "javascript:void(0)" ) { return ; } link.addEventListener("click", event => { event.preventDefault(); trackThisLink(link); }); trackedSet.push(link); }); function trackThisLink(link) { if ( !link ) { return ; } let linkData = {}; let href = link.getAttribute("href"); if ( /^#/.test(href) ) { linkData = intraLinkData(link); } else { if ( /^\//.test(href) ) { linkData = interLinkData(link); } else { href = new URL(href); if ( href.origin === window.location.origin ) { linkData = interLinkData(link); } else { linkData = externalLinkData(link); } } } sendTrackedLinkData(link, linkData); } function intraLinkData(link) { const href = link.getAttribute("href"); const title = getLinkElementTitle(link); return { "type": "intra", "linkTitle": title, "destinationId": href, "meta": { "id": link.getAttribute("id") || "", "classes": link.getAttribute("class") || "", "_parent": { "id": link.parentElement.getAttribute("id") || "", "classes": link.parentElement.getAttribute("class") || "", }, }, }; } function getLinkElementTitle(link) { let title = link.getAttribute("title"); title = title || link.textContent; const img = link.querySelector("img"); if ( img ) { title = title || img.getAttribute("alt"); } title = title || "N/A - Link text is unknown"; return title.trim(); } function interLinkData(link) { const href = link.getAttribute("href"); const title = getLinkElementTitle(link); const newTab = link.getAttribute("target") === "_blank"; return { "type": "internal", "linkTitle": title, "destination": href, "destinationPath": new URL(href, window.location.origin).pathname, "newTab": newTab, "meta": { "id": link.getAttribute("id") || "", "classes": link.getAttribute("class") || "", "_parent": { "id": link.parentElement.getAttribute("id") || "", "classes": link.parentElement.getAttribute("class") || "", }, }, }; } function externalLinkData(link) { const href = link.getAttribute("href"); const title = getLinkElementTitle(link); const newTab = link.getAttribute("target") === "_blank"; const relAttribute = link.getAttribute("rel").toLowerCase(); return { "type": "external", "linkTitle": title, "destination": href, "destinationOrigin": new URL(href).origin, "newTab": newTab, "isNoFollow": relAttribute.includes("nofollow"), "isSponsored": relAttribute.includes("sponsored"), "isNoReferer": relAttribute.includes("noreferer"), "meta": { "id": link.getAttribute("id") || "", "classes": link.getAttribute("class") || "", "_parent": { "id": link.parentElement.getAttribute("id") || "", "classes": link.parentElement.getAttribute("class") || "", }, }, }; } function sendTrackedLinkData(link, linkData) { try { rudderanalytics.track( 'linkClicked', linkData, simulateLinkClick(link) ); } catch(_) { simulateLinkClick(link); } } function simulateLinkClick( link ) { if ( link.href ) { link.target === '_blank' ? window.open(link.href, '_blank') : window.location.href = link.href; } } window.addEventListener("scroll", function(_) { var h = document.documentElement, b = document.body, st = 'scrollTop', sh = 'scrollHeight'; var percent = (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100; if (percent >= 24.99 && !trackedSet.includes('scrolled-25')) { trackScrollEvent('scrolled-25'); } else if (percent >= 49.99 && !trackedSet.includes('scrolled-50')) { trackScrollEvent('scrolled-50'); } else if (percent >= 74.99 && !trackedSet.includes('scrolled-75')) { trackScrollEvent('scrolled-75'); } else if (percent >= 99.00 && !trackedSet.includes('scrolled-100')) { trackScrollEvent('scrolled-100'); } }); function trackScrollEvent(eventName) { try { rudderanalytics.track( eventName, {} ); } catch(_) {} finally { trackedSet.push(eventName); } } window.onload = function() { var trackDates = { 'datePublished': '', 'dateModified': '' }; document.querySelectorAll("script[type='application/ld+json']") .forEach(function(script) { var jsonString = script.innerHTML; var json = JSON.parse(jsonString); if ( json ) { if ( json.hasOwnProperty("dateModified") ){ trackDates['dateModified'] = json['dateModified']; } if ( json.hasOwnProperty('datePublished') ) { trackDates['datePublished'] = json['datePublished']; } } }); rudderanalytics.page( document.title, trackDates ); if ( !sessionStorage.tabID ) { sessionStorage.tabID = Math.floor(Math.random() * 10e9); } const url = window.location.protocol + '//' + window.location.host + window.location.pathname; const hashedUrl = Math.abs(hashString(url)); let pageHistoryStack = sessionStorage.getItem("pageHistory") || '[]'; pageHistoryStack = JSON.parse(pageHistoryStack); let pageHistoryStackSize = sessionStorage.getItem("pageHistoryStackSize") || "0"; pageHistoryStackSize = parseInt(pageHistoryStackSize); if ( pageHistoryStack.length <= 0 ) { beginUserJourney(); pageHistoryStack.push(hashedUrl); } else { trackUserEnRoute( pageHistoryStackSize > pageHistoryStack.length ); if ( pageHistoryStack[pageHistoryStack.length - 1] !== hashedUrl ) { pageHistoryStack.push(hashedUrl); } } sessionStorage.setItem("pageHistory", JSON.stringify(pageHistoryStack)); sessionStorage.setItem("pageHistoryStackSize", pageHistoryStack.length); }; function hashString(str) { return str.split('').reduce((prevHash, currVal) => (((prevHash << 5) - prevHash) + currVal.charCodeAt(0))|0, 0); } function beginUserJourney() { const url = window.location.protocol + '//' + window.location.host + window.location.pathname; setTimeout( function() { rudderanalytics.track( "userJourneyStarted", { anonymousId: rudderanalytics.getAnonymousId(), prevPage: "", currPage: window.location.href, sessionTabId: sessionStorage.tabID, } ); sessionStorage.setItem("currPage", url); }, 500 ); } function trackUserEnRoute( userClickedBack = false ) { const url = window.location.protocol + '//' + window.location.host + window.location.pathname; setTimeout( function() { rudderanalytics.track( "userEnRoute", { anonymousId: rudderanalytics.getAnonymousId(), prevPage: sessionStorage.getItem("currPage") || "", currPage: window.location.href, clickedBack: userClickedBack, sessionTabId: sessionStorage.tabID, }, function() { console.log("enRouteTracked:"); } ); sessionStorage.setItem("currPage", url); }, 500 ); } document.addEventListener('keydown', function(event) { if ( event.which == 116 || ( event.which == 82 && event.ctrlKey ) ) { rdTracker.isAboutToRefresh = true; } }); window.onbeforeunload = function() { let triggeredBy = document.activeElement; if ( triggeredBy.hasAttribute("href") && ( /^\//.test( triggeredBy.getAttribute("href") ) || triggeredBy.getAttribute("href").startsWith(window.location.origin) ) && !rdTracker.isAboutToRefresh && !rdTracker.hasMouseLeftWindow ) { // Do nothing at this point } else { let pageHistoryStack = sessionStorage.getItem("pageHistory") || '[]'; pageHistoryStack = JSON.parse(pageHistoryStack); if ( pageHistoryStack.length > 0 ) { pageHistoryStack.pop(); sessionStorage.setItem("pageHistory", JSON.stringify(pageHistoryStack)); } } } document.addEventListener('copy', function(event) { var selectedText = window.getSelection().toString(); selectedText = selectedText.replace(/\u200B/g, ""); rudderanalytics.track( "copiedToClipboard", { sessionTabId: sessionStorage.tabID, clipboardText: selectedText, } ); }); document.querySelectorAll('form') .forEach(function(form) { form.addEventListener('submit', function(event) { var formId = form.getAttribute('id') || ''; if ( formsToNotTrack.includes(formId) ) { return ; } event.preventDefault(); rudderanalytics.track( "formSubmit", { sessionTabId: sessionStorage.tabID, formId: formId, formAction: form.getAttribute('action') || '', } ); setTimeout(function() { HTMLFormElement.prototype.submit.call(form); }, 1000); }); }); document.querySelectorAll('input[type=radio], input[type=checkbox') .forEach(function(input) { input.addEventListener('change', function() { rudderanalytics.track( "radioCheckboxChanged", { sessionTabId: sessionStorage.tabID, inputId: input.getAttribute('id') || '', inputName: input.getAttribute('name') || '', isChecked: input.checked, } ); }); });
g
You're on the right track. I'd suggest to take one event at a time. Whichever event you had earlier, set that event up now using RudderStack (RS) JS SDK. Test it on GoogleAnalytics if you're receiving the event or not. If yes, move on to setting up the next event
f
Pradeedp
i already sent eventss..
events are received...
g
While doing this, you might need Google Anaytics knowledgeable, which you can find here https://developers.google.com/analytics/devguides/collection
f
my points is if i am sending the rigth ones
this is a joke, with respect
you sell RD as an alternative
and this is the result
g
I'm unable to understand your query. I'll let others pitch in if they can.
f
Pradeep, it is very easy, If you want to sell your product...
and you HAVE NOT any documentacion about how to use GA4 in the same way using RD....
who is going to buy it?
i spent hundred of hours...already
i i really love your idea
more tha segment.io
but, customer attention...
it is very different
ny statement is very clear
i need to remove my GA4 script , add RD scripts and be able to send events to GA4 with the same result GA4 has, and at the same time send to BQ
it is very clear statement
can your product do that or nor?
it is very simpel
simple
thi is what i get with RD in GA4
g
RudderStack does not provide the dashboard to visualise the data. RudderStack can help you send the events data.
f
uffff.....forget it
we go to segment
many thanks
my question is
your schemas.... when i sent events
to GA4
with your format
i get a shit
then i need support
if i am doing sometign wrong
it very very simple
are your events tracking compatible with gA4 ?
g
Yes. It is compatible with GA4. GA4 destination is in beta as of now. So if you face issue with any particular event, please share that.