-
-
Notifications
You must be signed in to change notification settings - Fork 2
Blade Usage
Blade is the templating engine included with Laravel, offering a powerful and intuitive syntax for creating views. With the Laravel UTM-Parameters package, you can seamlessly integrate UTM parameter tracking into your Blade views to personalize content, display targeted messages, or adjust layouts based on referral sources.
Before using Blade directives, ensure that you have included the helper functions provided by the Laravel UTM-Parameters package. These functions allow you to retrieve and manipulate UTM parameters within your Blade views.
The get_all_utm() function retrieves an array containing all UTM parameters captured in the current session. This function is useful when you need to access multiple UTM parameters simultaneously.
@foreach (get_all_utm() as $key => $value)
<p>{{ $key }}: {{ $value }}</p>
@endforeach
The get_utm($key) function retrieves the value of a specific UTM parameter specified by the $key parameter. If the UTM parameter is not found, null is returned.
<p>You came from {{ get_utm('source') }}</p>
The has_utm($key, $value = null) function checks if a specific UTM parameter exists in the current session. Optionally, you can specify a $value parameter to check if the UTM parameter matches a specific value. It returns true if the UTM parameter exists (and optionally matches the specified value), otherwise false.
@if (has_utm('source', 'newsletter'))
<p>Welcome Newsletter Subscriber!</p>
@endif
@hasUtm('source', 'corporate-partner')
<div>Some corporate partner related stuff</div>
@endhasUtm
The has_not_utm($key, $value = null) function is the inverse of has_utm(). It returns true if the specified UTM parameter does not exist (or does not match the specified value, if provided), otherwise false.
@if (has_not_utm('source', 'social'))
<p>You did not come from a social media campaign.</p>
@endif
@hasNotUtm('term')
<p>You have any term.</p>
@endhasNotUtm
Blade's intuitive syntax and flexibility make it easy to integrate UTM parameter tracking into your Laravel views. By leveraging Blade directives and helper functions provided by the Laravel UTM-Parameters package, you can create dynamic and personalized user experiences based on referral sources and campaign data.