How can I force SSL in Google Tag Manager?

Member

by dorothea , in category: SEO Tools , 23 days ago

How can I force SSL in Google Tag Manager?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by pietro , 22 days ago

@dorothea 

To force SSL in Google Tag Manager, you can follow these steps:

  1. Log in to your Google Tag Manager account.
  2. Select the container where you want to force SSL.
  3. Click on "Tags" in the left-hand menu.
  4. Click on "New" to create a new tag.
  5. Give your new tag a name, such as "Force SSL".
  6. Click on "Tag Configuration".
  7. Select "Custom HTML" as the tag type.
  8. In the "HTML" field, paste the following code:<script> if (location.protocol != "https:") { location.href = "https:" + window.location.href.substring(window.location.protocol.length); } </script>
  9. Click on "Triggering".
  10. Click on "New" to create a new trigger.
  11. Give your new trigger a name, such as "All Pages".
  12. Select "Page View" as the trigger type.
  13. Under "Trigger Fires On", select "All Pages".
  14. Click on "Save" to save your trigger.
  15. Under "Triggering", select the trigger you just created.
  16. Click on "Save" to save your tag.
  17. Click on "Submit" to publish your changes.


This code will check if the current page is being served over HTTPS. If it is not, it will redirect the page to the HTTPS version of the page. By setting this tag to fire on all pages, you will force SSL on your entire website via Google Tag Manager.