I'm trying to load a datalayer after using gform_after_submission

Hello there!
I need to load a datalayer code after sending a successfully form
this is my code:

add_action('gform_after_submission_7', 'set_academy_title', 10, 2);

function set_academy_title($entry, $form)
{ ?>
<script type="text/javascript">
		window.dataLayer = window.dataLayer || [];
		dataLayer.push({
			'event': 'academy-subscription',
			'academyTitle': '<?php the_title(); ?>'
		});
	</script>
<?php }

everything is working good but this script is loading inside an iframe https://prnt.sc/th6hpl so i cant track the data
could you help me please?
thank you

Hello. gform_after_submission is disconnected from the form submission process, so it may not be happening when you think it should be. Try using the gform_confirmation_loaded filter, for AJAX enabled forms, or put that script in your confirmation text message. gform_after_submission is not the right place.