CMS Development

KDuffie
Member

CMS: App needs to add embed code into page <head>

We are both a Hubspot customer and are developing a Hubspot app that our customers using Hubspot will use.  Our service integrates with our customer's website from inside the browser.  We need to be able to add our embed code into the <head> of all of their pages.  The customer could do this manually via a setting, but we'd prefer that having installed our app, it could add that embed code for them.  In WordPress this is easy as there are hooks for a plugin to add code into the head.  Can you advise as to the best way to accomplish this with Hubspot?  The app could modify their templates via the API, but this isn't good because if they uninstall the app, they would want those modifications to automatically disappear.

0 Upvotes
7 Replies 7
KDuffie
Member

CMS: App needs to add embed code into page <head>

Wendy, thanks for your answer.   If I understand how things work correctly, I don't think this is going to work if someone is using a built-in template.  From what I can see from the APIs, it doesn't look like these built-in templates are even returned via the API.  And, even if they were, I don't believe I would be allowed to update a built-in template.  That would mean that I have to detect built-in templates, clone them, update them, and then update the references to the built-in template to point to the new cloned template.  That starts to get more and more problematic for customers.

 

Frankly, even if we did that work to create cloned templates and switch them, I doubt that you or your customers would really want us doing that to simply add a simple embed code.  Do you think Hubspot is amenable to adding a feature for this?   I think it could be very simple: an API for listing and updating <head> fragment contributions.

WendyGoh
HubSpot Employee
HubSpot Employee

CMS: App needs to add embed code into page <head>

Hey @KDuffie

 

I'd be happy to provide some insights here.

 

While currently there isn't a HubSpot endpoint to add embed code into pages' <head> tag. I believe using this endpoint would work and to your point if customer uninstall the app, the changes made to the template would still be present and wouldn't get deleted. Let me know if this address your concern and/or if there's any queries on this! Happy to discuss further!

KDuffie
Member

CMS: App needs to add embed code into page <head>

The app precheck sounds like a good idea.  But I'm not aware that there is any API available within HubL to find out if a given app is installed or not.   So, yes, some kind of workflow seems like the only approach, but very ugly that you'd be asking a customer to undo a change that you made to their templates.  If I were that customer, I'd certainly be unhappy.

 

My sense is that Hubspot has just not anticipated our use case.  We are a SaaS that wants to offer added value to websites, but we don't want to ask customers to change the themes or templates they are using.  I won't try to defend the WordPress plugin model or page lifecycle model, but it is a much better match for cases like ours.

Jake_Lett
Guide | Partner
Guide | Partner

CMS: App needs to add embed code into page <head>

If you modify the template is there a way to check if your app is installed before it fires? That way if the app is uninstalled it will still be loaded but not fired? Not ideal but wondering if that would work.

 

Another idea is to have a workflow that emails customers who have uninstalled the app if you are able and inform them to remove the code from their templates.

0 Upvotes
Jake_Lett
Guide | Partner
Guide | Partner

CMS: App needs to add embed code into page <head>

I am not that familiar with the app development process but does it allow you to add HubL? 

 

https://developers.hubspot.com/docs/cms/hubl/tags#require-head

0 Upvotes
KDuffie
Member

CMS: App needs to add embed code into page <head>

A Hubspot app is essentially a way to use OAuth to get a token that can be used to access the REST APIs for the site.  When someone adds an app to their site, a call is made to the app provider's site that starts an oauth flow culminating in the provider getting this token.  The REST APIs provide access to lots of the Hubspot functionality, depending on which scopes were requested by the app and approved by the initiator.  In answer to your question, these APIs include, among other things, the ability to access content and to list and/or update templates (see https://legacydocs.hubspot.com/docs/methods/templates/put_templates_template_id).  It is within those templates where someone could, theoretically, add HubL.   But, as I mentioned in my question, there are several problems with doing that -- not least of which is that if the app is ever removed, the provider would have no way to then remove whatever modifications were made.  

 

What is really needed is an API that allows the provider to set various properties that would affect how pages are rendered (including contributions to <head> for example) knowing that these properties will be used only while the app remains active and authorized.  

 

However, if you know of some other way to accomplish the goal, I'd very much appreciate finding that out.

natsumimori
Community Manager
Community Manager

CMS: App needs to add embed code into page <head>

Hi @KDuffie , thank you for reaching out to the HubSpot Community.

 

@Theodor and @Jake_Lett , is this something you guys are familiar with? Would you mind sharing your advice for @KDuffie ?

0 Upvotes