Learn business growth with Google Analytics 4 Forums Google Analytics 4 Successful Tracking of Google Analytics Events with Selenium Using C#

  • Successful Tracking of Google Analytics Events with Selenium Using C#

    Posted by Grayson on 25 November 2022 at 4:23 pm

    “Hey folks, I’m messing around with a project where I’m trying to snag some Google Analytics events from the network logs of an ecommerce site. When I do it old school and manually track things down, I see the events no problem, but when I automate it with Chrome, the events are putting on their cloaks of invisibility (meaning, I don’t see ’em at all).

    Just so you know what I’ve already done, I’ve got my network logs and performance logs switched on. Should I be looking at some other settings that need to be flipped or do I have to do some tweaking somewhere else? Seriously, any tips would be a huge help, guys. Thumbs-up emoji!

    Oh, and here’s my code if you want to layer in the technical bit:

    `
    public bool GAEventslogs(string gaEvent)
    {
    var logs = Site.Driver.Manage().Logs.GetLog(“performance”);
    for (int i = 0; i < logs.Count; i++)
    {
    Console.WriteLine(logs[i].Message);
    if (logs[i].Message.Contains("https://analytics.google.com/g/collect&quot😉 && logs[i].Message.Contains(gaEvent))
    {
    return true;
    }
    }
    return false;
    }
    `
    And if it helps, here’s a link to the GA events that I’ve been able to manually pick up: [GA events showing manually](https://i.stack.imgur.com/EVERi.png)”

    Brett replied 11 months, 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Cameron

    Member
    1 June 2023 at 11:18 pm

    Your issue might be due to Google Analytics sending data to a different URL. In your code, you’re specifically looking for “https://analytics.google.com/g/collect” in the logs. However, Google Analytics has been known to send data to “https://www.google-analytics.com/j/collect.” If this is the case, your condition wouldn’t be met, hence the invisibility of your logs. You should adjust your code accordingly to include this URL as well. This way, your code searches for both known URLs where GA could be sending the data. Make sure to include other potential URLs as well as Google could expand the list in future. Also, ensure that your automated Chrome settings allow for complete visibility and access of network logs. You can always refer to Google’s documentation or their troubleshooting guide for more assistance.

  • Brett

    Member
    15 June 2023 at 3:25 am

    It seems like you’re trying to capture Google Analytics events from the network logs of a website, but you’re running into a problem where the events don’t appear when you automate the process with Chrome, despite appearing when you track them manually. You’ve already turned on your network and performance logs, which was a good initial step. The issue might be related to the settings or it could require more advanced modifications. The code you shared takes a look at the performance logs, scanning for messages that contain both “https://analytics.google.com/g/collect” and the specific Google Analytics event. If the event isn’t found, it returns false. One possible solution could be to double-check whether the events should in fact be part of the performance logs, as well as to validate if the URL and event string you’re using are absolutely correct.

Log in to reply.