• Resolved zupaazhai

    (@zupaazhai)


    I found issue Javascript error “Uncaught SyntaxError: expected expression, got ‘&’” when using with Plugin Google Analytics for WooCommerce

    it renders gtag function with HTML encoded value

    gtag("event", "page_view", {send_to: "GLA"});

    I try to deep in code of plugin, I found interesting in 2 methods in file /src/Google/GoogleSiteTag.php

    at function display_page_view_event_snippet it pass value of add_inline_event_script with string 'gtag("event", "page_view", {send_to: "GLA"});'

    private function display_page_view_event_snippet(): void {
     if ( ! is_cart() ) {
        $this->add_inline_event_script( 'gtag("event", "page_view", {send_to: "GLA"});' );
        return;
    }
    ...

    then in method add_inline_event_script , inline script that pass as parameter will be wrap with function esc_js , so quote symbol will be rendered as " then this leads to JS error.

    I not sure is this can be defect or bug when use these plugin together? let me know if Developer team see this topic and anyone found out solution

    My Environment

    WordPress – 6.4.3
    Google Listings and Ads – 2.6.2
    Google Analytics for WooCommerce – 2.0.3

    • This topic was modified 8 months, 1 week ago by zupaazhai.
    • This topic was modified 8 months, 1 week ago by zupaazhai.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Uncaught SyntaxError: got ‘&’’ is closed to new replies.