-
Utilizing Google Tag Manager's REST APIs to Generate GA4 Tags
Hey, we’ve got a bit of a situation. We love our website and now we’re looking to get our Universal Analytics tags switched over to GA4 tags, but we’re all about that work smarter not harder lifestyle – no manual migrating for us! We stumbled upon these super nifty Google Tag Manager (GTM) REST APIs for creating tags, triggers, and so on, and it’s been pretty great so far. In fact, I got really stoked because I was able to whip up a Universal Tag using the REST API, you can check out how I did it here.
But I’ve hit a bit of a roadblock, I can’t seem to create GA4 tags from the GTM REST APIs. Here’s what I tried:
{ "name": "GA4 Tag", "type": "gaawe", "parameter": [ { "type": "template", "key": "measurement_id", "value": "G-1234567890" }, { "type": "template", "key": "event_name", "value": "page_view" }, { "type": "list", "key": "custom_dimensions" } ] }
And BAM! A 400 Bad request error hit me like a ton of bricks. Here’s the scoop:
{ "error": { "code": 400, "message": "vendorTemplate.parameter.measurementId: The value must not be empty.nvendorTemplate.parameter.eventName: The value must not be empty.n", "errors": [ { "message": "vendorTemplate.parameter.measurementId: The value must not be empty.nvendorTemplate.parameter.eventName: The value must not be empty.n", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }
Now, I’m no Sherlock, but the documentation (link) doesn’t mention anything about
vendorTemplate
as a required or optional parameter. However, being the brave soul that I am, I tried addingvendorTemplate
as an attribute in the request payload anyways. And guess what it says:Property "vendorTemplate" does not exist in object specification
.Now I’m feeling a bit stuck. Can’t create a GA4 tag using REST API, which puts my dream of migrating from Universal Tag to GA4 tags on the back burner.
If anyone out there can lend a hand with creating GA4 tags and migrating Universal Analytics Tags to GA4 tags using REST APIs, it would be a lifesaver! I even tried to solve the
vendorTemplate
error by adding it to the request payload, to no avail. So, my friends, any hints, tips, or tricks are warmly welcomed — help me make this magic happen!
Log in to reply.