@@ -74,6 +74,7 @@ Please check Google site: https://developers.google.com/recaptcha/docs/faq
74
74
- Support custom implementation on request method interface
75
75
- Fully supported Vue component
76
76
- IP skip list supported
77
+ - Support script to be placed in the background of pages for analytics
77
78
78
79
## Requirement
79
80
@@ -92,7 +93,7 @@ This package requires the following dependencies:
92
93
Via Composer
93
94
94
95
``` sh
95
- $ composer require timehunter/laravel-google-recaptcha-v3 " ~2.2.0 " -vvv
96
+ $ composer require timehunter/laravel-google-recaptcha-v3 " ~2.2.5 " -vvv
96
97
```
97
98
98
99
If your Laravel framework version <= 5.4, please register the service provider under your config file: /config/app.php, otherwise please skip it.
@@ -129,7 +130,7 @@ After installation, you should see a googlerecaptchav3.php in your app/config fo
129
130
## Configurations <a name =" settings " />
130
131
### Setting up your Google reCAPTCHA details in config file
131
132
132
- Please register all details in config for site_key and secret_key .
133
+ Please register all details in config for host_name, site_key, secret_key and site_verify_url .
133
134
134
135
Specify your Score threshold and action in 'setting', e.g.
135
136
``` php
@@ -138,12 +139,21 @@ Specify your Score threshold and action in 'setting', e.g.
138
139
'action' => 'contact_us', // Google reCAPTCHA required paramater
139
140
'threshold' => 0.2, // score threshold
140
141
'is_enabled' => false // if this is true, the system will do score comparsion against your threshold for the action
141
- ]
142
+ ],
143
+ [
144
+ 'action' => 'signup',
145
+ 'threshold' => 0.2,
146
+ 'score_comparision' => true
147
+ ],
142
148
]
143
149
```
144
150
Note: if you want to enable Score Comparision, you also need to enable is_score_enabled to be true.
145
151
``` php
146
- 'is_score_enabled' = true
152
+ 'setting' = [
153
+ ...
154
+ 'is_score_enabled' = true
155
+ ...
156
+ ]
147
157
```
148
158
149
159
For score comparision, all actions should be registered in googlerecaptchav3 config file under 'setting' section.
@@ -216,66 +226,40 @@ If you manually assign a value to setScore($score), the code will fully skip you
216
226
217
227
218
228
## Blade Usage <a name =" blade-basic-usage " />
229
+
219
230
### Display reCAPTCHA v3
220
231
221
- #### Blade
222
- Include div with an ID inside your form, e.g.
232
+ #### Blade for Background (optional)
223
233
224
- ``` html
225
- <div id =" contact_us_id" ></div >
226
- ```
234
+ It's recommended to include reCAPTCHA v3 on every page which can help you get the most context about interactions for analytics.
227
235
228
- Include Template script in your bottom/header of your page, params should follow 'ID'=>'Action', e.g.
236
+ In your main homepage or layout page, put the following script at the bottom of your page:
229
237
230
- ``` PHP
231
- {!! GoogleReCaptchaV3::render(
232
- [
233
- 'contact_us_id'=>'contact_us', // the div id=contact_us_id maps to action name contact_us
234
- 'signin_id'=>'registration', // the div id=signin_id maps to action name registration
235
- 'register_id'=>'registration' // the div id=register_id maps to action name registration
236
- ]) !!}
238
+ ``` html
239
+ {!! GoogleReCaptchaV3::background() !!}
237
240
```
238
241
239
- #### Example Usage
240
-
241
- Register your action in config, also enable score and set up your own site key and secret key:
242
+ Note: the above script MUST be called after GoogleReCaptchaV3::render(), otherwise the google script might run multiple times.
242
243
244
+ You can also set the background reCAPTCHA as hidden or visible(bottomright):
243
245
244
246
``` php
245
- 'setting' => [
246
- [
247
- 'action' => 'contact_us',
248
- 'threshold' => 2,
249
- 'score_comparision' => true
250
- ],
251
- [
252
- 'action' => 'signup',
253
- 'threshold' => 0.2,
254
- 'score_comparision' => true
255
- ],
256
- ]
247
+ ...
248
+ 'background_badge_display' => true,
249
+ ...
257
250
```
251
+
252
+ #### Blade for Form & Action
258
253
259
- Register two routes in web.php
260
- ``` php
261
- Route::get('/index', 'ReCaptchaController@index');
262
- Route::post('/verify', 'ReCaptchaController@verify');
263
- ```
254
+ Include div with an ID inside your form, e.g.
264
255
265
- Create two functions in controller:
266
- ``` php
267
- public function verify(Request $request)
268
- {
269
- dd(GoogleReCaptchaV3::verifyResponse($request->input('g-recaptcha-response'))->getMessage());
270
- }
271
- public function index(Request $request)
272
- {
273
- return view('index');
274
- }
256
+ ``` html
257
+ <div id =" contact_us_id" ></div >
275
258
```
276
259
277
- Create your form in index.blade.php:
278
- ``` html
260
+ Include GoogleReCaptchaV3::render() script after your form, params should follow 'ID'=>'Action', e.g.
261
+
262
+ ``` html
279
263
{{--if laravel version <=5.6, please use {{ csrf_field() }}--}}
280
264
281
265
<form method =" POST" action =" /verify" >
@@ -294,11 +278,8 @@ Create your form in index.blade.php:
294
278
{!! GoogleReCaptchaV3::render(['contact_us_id'=>'contact_us', 'signup_id'=>'signup']) !!}
295
279
```
296
280
297
- The backend request will receive a value for 'g-recaptcha-response'.
298
-
299
- Go to /index and click submit button on contact us form and you should see an error message that 'Score does not meet the treshhold' because the threshold >2. You can play around the controller to see all outcomes. Importantly, you need to wait the script to be loaded before clicking the submit button.
300
281
301
- ## Badge Display < a name = " badge-display " />
282
+ ### Badge Display for Form & Action
302
283
303
284
If your settings were not reflected, please run php artisan config: cache to clear cache.
304
285
@@ -338,7 +319,7 @@ Custom
338
319
2 . Do Styling/CSS on its div element
339
320
340
321
341
- ## Vue Usage (Pacakge version >= 2.2.0) <a name =" vue-usage " />
322
+ ## Vue Usage (Package version >= 2.2.0) <a name =" vue-usage " />
342
323
343
324
The package provides a lightweight vue component. You need to publish the vue component before playing around it.
344
325
0 commit comments