Hi. I setup Google analytics G4 with rudderstack a...
# support
s
Hi. I setup Google analytics G4 with rudderstack and am receiving hits/events but no referrer or country information. Is there something I missed in the setup?
Any updates?
g
Can you share more information to debug this. Are you using device or cloud mode?
s
Cloud mode
s
Below I have written a piece of code to fetch the user’s location
Copy code
export const location =  {};

function getLocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(getPosition);
    } else {
      return "Geolocation is not supported by this browser.";
    }
}

getLocation();

function getPosition(position) {
    location.latitude = position.coords.latitude;
    location.longitude = position.coords.longitude;
}
You can then pass the lat/long details to the event.
s
Ok so I understand now you wanted me to write up a transformation (thanks largely to chatGPT) please going forward assume I know nothing about Rudderstack or code. So I’d write a transformation that captures the geolocation. I see this is one of them recommended by Rudderstack.
Copy code
export async function transformEvent(event, metadata) {
    if (event.request_ip) {
        const res = await fetch("https://ip2.app/info.php?ip=" + event.request_ip);
        event.context.geolocation = res;
    }
    return event;
}
If I add IP address to the JSON playground in the transformation builder I get no response.
So how does event.request_ip get the information from the browser?
Then how does Google know what to do with the information I pass to the event?
Aren’t there basic transformation scripts I can use to send the basic event information to GA4? I mean the script you provided doesn’t work either “navigator” is not recognised. So how does your system do this? I am keen to learn but am getting nothing here that helps do something that your competitors (GTM/Segment) do out of the box. I understand certain params like product information require us to custom code things, but locations? referrers? I mean these are ordinarily handled automatically.