Skip to content

Commit

Permalink
Update: support component attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jordyvanderhaegen committed Dec 4, 2023
1 parent f8636c5 commit 849d909
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
4 changes: 3 additions & 1 deletion resources/views/components/data-layer-variable.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script>
@props(['arguments'])

<script {{ $attributes }}>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(@json((object) $arguments));
</script>
7 changes: 6 additions & 1 deletion resources/views/components/facebook-pixel-script.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<script>
@props([
'pixelId',
'advancedMatchingData',
])

<script {{ $attributes }}>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<script>
@props([
'eventType',
'eventName',
'customData',
'eventData',
])

<script {{ $attributes }}>
fbq('{{ $eventType }}', '{{ $eventName }}', @json((object) $customData), @json((object) $eventData));
</script>
13 changes: 13 additions & 0 deletions tests/Feature/View/Components/DataLayerVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ public function it_can_render_anonymously()

$view->assertSee('window.dataLayer.push({"event":"contact"});', false);
}

/** @test */
public function it_can_pass_component_attributes()
{
$view = $this->blade('
<x-conversions-api::data-layer-variable
:arguments="[]"
class="my-class"
/>
');

$view->assertSee('<script class="my-class">', false);
}
}
13 changes: 13 additions & 0 deletions tests/Feature/View/Components/FacebookPixelScriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ public function it_can_render_the_view_passing_custom_data()

$component->assertSee("fbq('init', '744689831385767', {\"em\":\"[email protected]\"});", false);
}

/** @test */
public function it_can_pass_component_attributes()
{
$view = $this->blade('
<x-conversions-api::data-layer-variable
:arguments="[]"
class="my-class"
/>
');

$view->assertSee('<script class="my-class">', false);
}
}
16 changes: 16 additions & 0 deletions tests/Feature/View/Components/FacebookPixelTrackingEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,20 @@ public function it_can_render_anonymously()

$view->assertSee("fbq('track', 'Purchase', {}, {});", false);
}

/** @test */
public function it_can_pass_component_attributes()
{
$view = $this->blade('
<x-conversions-api::facebook-pixel-tracking-event
eventType="track"
eventName="Purchase"
:customData="[]"
:eventData="[]"
class="my-class"
/>
');

$view->assertSee('<script class="my-class">', false);
}
}

0 comments on commit 849d909

Please sign in to comment.