ViewContent custom parameters appear incorrect in meta pixel helper chrome plugin

Created on 22 November 2023, about 1 year ago
Updated 2 July 2024, 7 months ago

Problem/Motivation

Using the meta pixel helper chrome plugin, the custom params of the viewContent event don't appear to be sending correctly.
see the screenshot for the output I am seeing. This is happening on every node page.

Steps to reproduce

Install the module
add your pixel id
view a node page
look at the output of the meta pixel plugin

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code (General)

Created by

πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @loze
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    it appears that in the call to fbq("track", event['event'], event['data']); in facebook_pixel.js
    event['data'] is a string and not a json object.

    changing this line to fbq("track", event['event'], JSON.parse(event['data'])); seems to fix it.

    I will provide a patch

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    23 pass
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    With the patch, this is the output on the pixel helper now. Which seems correct.

  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles
  • Assigned to Grevil
  • Status changed to Needs work 7 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Yea, this is quite weird, the approach here is incorrect though:

    Inside "facebook_pixel.module" line 51, we have the following code:

          'data' => Xss::filter(json_encode($event['data'])),
    

    This doesn't make much sense as Xss::filter returns a string. Instead, we should turn the statements around.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    last update 7 months ago
    23 pass
  • Status changed to Needs review 7 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    This should do the trick. Feel free to test it @loze!

  • Issue was unassigned.
  • πŸ‡©πŸ‡ͺGermany Grevil
  • Status changed to Needs work 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    Thanks Grevil, I tried your MR and get the following error now

    The website encountered an unexpected error. Try again later.
    
    TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen() (line 395 of core/lib/Drupal/Component/Utility/Unicode.php).
    Drupal\Component\Utility\Unicode::validateUtf8(Array) (Line: 65)
    Drupal\Component\Utility\Xss::filter(Array) (Line: 52)
    facebook_pixel_page_attachments(Array) (Line: 311)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}(Object, 'facebook_pixel') (Line: 388)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith('page_attachments', Object) (Line: 308)
    Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 285)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 284)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 193)
    Drupal\cleantalk\EventSubscriber\BootSubscriber->handle(Object, 1, 1) (Line: 53)
    Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
  • πŸ‡©πŸ‡ͺGermany Grevil

    My apologies @loze, your original changes were correct, while mine are not. I think I simply rushed it and came to an incorrect solution.
    We always get a JSON string inside our js, which we need to parse to "real" JSON, like your original changes suggested. I'll revert my changes.

  • Status changed to RTBC 7 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    All green and works as expected. Thanks!

  • Status changed to Fixed 7 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil
  • πŸ‡©πŸ‡ͺGermany Grevil

    Oh, this was already fixed through πŸ› Event data should be passed as object Fixed . I thought the gitlab diff might be buggy. Oh, well.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024